From c7b4c2beaf7cb26a7856a1a4d84d6a912fccd5e5 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 2 Mar 2017 17:33:58 -0800 Subject: [PATCH] Require ctrl for link clicks Fixes #578 --- src/Linkifier.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 0b144cfd..41a362b5 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -218,9 +218,13 @@ export class Linkifier { const element = this._document.createElement('a'); element.textContent = uri; if (handler) { - element.addEventListener('click', () => { - // Only execute the handler if the link is not flagged as invalid - if (!element.classList.contains(INVALID_LINK_CLASS)) { + element.addEventListener('click', (event: KeyboardEvent) => { + // Don't execute the handler if the link is flagged as invalid + if (element.classList.contains(INVALID_LINK_CLASS)) { + return; + } + // Require ctrl on click + if (event.ctrlKey) { handler(uri); } }); @@ -228,6 +232,13 @@ export class Linkifier { element.href = uri; // Force link on another tab so work is not lost element.target = '_blank'; + element.addEventListener('click', (event: KeyboardEvent) => { + // Require ctrl on click + if (!event.ctrlKey) { + event.preventDefault(); + return false; + } + }); } return element; }