From ad535a9f2823122ce25e69fc977d52f3f717da2b Mon Sep 17 00:00:00 2001 From: Matthew Chan <> Date: Wed, 19 Jan 2022 00:15:35 -0800 Subject: [PATCH] Fix middle click to open link. --- main.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index 4363797..5dd26ff 100644 --- a/main.ts +++ b/main.ts @@ -68,7 +68,16 @@ export default class Linkify extends Plugin { // Cmd/Ctrl + click or middle click on linkified text to open the link. this.cmdClick = navigator.platform.startsWith("Mac"); - this.registerDomEvent(document, 'click', this.openLink.bind(this)); + this.registerDomEvent(document, 'click', evt => { + if (this.cmdClick ? evt.metaKey : evt.ctrlKey) { + this.openLink(evt); + } + }); + this.registerDomEvent(document, 'auxclick', evt => { + if (evt.button == 1) { + this.openLink(evt); + } + }) } async loadSettings() { @@ -89,8 +98,7 @@ export default class Linkify extends Plugin { // Opens linkified text as a link. openLink(evt: MouseEvent) { - if (((this.cmdClick ? evt.metaKey : evt.ctrlKey) || evt.button == 1) && - evt.target instanceof HTMLSpanElement && + if (evt.target instanceof HTMLSpanElement && evt.target.className == "cm-link linkified") { let m = this.matchRule(evt.target.innerText); if (m != null) { @@ -156,6 +164,7 @@ export default class Linkify extends Plugin { } } + } class LinkifySettingTab extends PluginSettingTab {