Skip to content

Commit

Permalink
Fix middle click to open link.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Chan committed Jan 19, 2022
1 parent 3962a82 commit ad535a9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -156,6 +164,7 @@ export default class Linkify extends Plugin {
}
}


}

class LinkifySettingTab extends PluginSettingTab {
Expand Down

0 comments on commit ad535a9

Please sign in to comment.