1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

use Cmd key for only macOS

This commit is contained in:
Baptiste Augrain
2018-09-09 11:12:47 +02:00
parent dbe1721d50
commit a6a1291d0e

View File

@@ -12,6 +12,9 @@
const shell = require('electron').shell const shell = require('electron').shell
const yOffset = 2 const yOffset = 2
const macOS = global.process.platform === 'darwin'
const modifier = macOS ? 'metaKey' : 'ctrlKey'
class HyperLink { class HyperLink {
constructor(cm) { constructor(cm) {
this.cm = cm this.cm = cm
@@ -29,7 +32,7 @@
this.tooltip.setAttribute('cm-ignore-events', 'true') this.tooltip.setAttribute('cm-ignore-events', 'true')
this.tooltip.appendChild(this.tooltipContent) this.tooltip.appendChild(this.tooltipContent)
this.tooltip.appendChild(this.tooltipIndicator) 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('mousedown', this.onMouseDown)
this.lineDiv.addEventListener('mouseenter', this.onMouseEnter, { this.lineDiv.addEventListener('mouseenter', this.onMouseEnter, {
@@ -55,8 +58,8 @@
return null return null
} }
onMouseDown(e) { onMouseDown(e) {
const { target, metaKey } = e const { target } = e
if (!metaKey) { if (!e[modifier]) {
return return
} }
@@ -68,11 +71,11 @@
} }
} }
onMouseEnter(e) { onMouseEnter(e) {
const { target, metaKey } = e const { target } = e
const url = this.getUrl(target) const url = this.getUrl(target)
if (url) { if (url) {
if (metaKey) { if (e[modifier]) {
target.classList.add('CodeMirror-activeline-background', 'CodeMirror-hyperlink') target.classList.add('CodeMirror-activeline-background', 'CodeMirror-hyperlink')
} }
else { else {
@@ -91,7 +94,7 @@
} }
onMouseMove(e) { onMouseMove(e) {
if (this.tooltip.parentElement === this.lineDiv) { if (this.tooltip.parentElement === this.lineDiv) {
if (e.metaKey) { if (e[modifier]) {
e.target.classList.add('CodeMirror-hyperlink') e.target.classList.add('CodeMirror-hyperlink')
} }
else { else {