Skip to content

Commit

Permalink
use Cmd key for only macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
daiyam committed Sep 9, 2018
1 parent dbe1721 commit a6a1291
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions extra_scripts/codemirror/addon/hyperlink/hyperlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
const shell = require('electron').shell
const yOffset = 2

const macOS = global.process.platform === 'darwin'
const modifier = macOS ? 'metaKey' : 'ctrlKey'

class HyperLink {
constructor(cm) {
this.cm = cm
Expand All @@ -29,7 +32,7 @@
this.tooltip.setAttribute('cm-ignore-events', 'true')
this.tooltip.appendChild(this.tooltipContent)
this.tooltip.appendChild(this.tooltipIndicator)
this.tooltipContent.textContent = 'Cmd + click to follow link'
this.tooltipContent.textContent = `${macOS ? 'Cmd(⌘)' : 'Ctrl(^)'} + click to follow link`

this.lineDiv.addEventListener('mousedown', this.onMouseDown)
this.lineDiv.addEventListener('mouseenter', this.onMouseEnter, {
Expand All @@ -55,8 +58,8 @@
return null
}
onMouseDown(e) {
const { target, metaKey } = e
if (!metaKey) {
const { target } = e
if (!e[modifier]) {
return
}

Expand All @@ -68,11 +71,11 @@
}
}
onMouseEnter(e) {
const { target, metaKey } = e
const { target } = e

const url = this.getUrl(target)
if (url) {
if (metaKey) {
if (e[modifier]) {
target.classList.add('CodeMirror-activeline-background', 'CodeMirror-hyperlink')
}
else {
Expand All @@ -91,7 +94,7 @@
}
onMouseMove(e) {
if (this.tooltip.parentElement === this.lineDiv) {
if (e.metaKey) {
if (e[modifier]) {
e.target.classList.add('CodeMirror-hyperlink')
}
else {
Expand Down

0 comments on commit a6a1291

Please sign in to comment.