From d0dd26dd1bbcd5c15d3a5553850e6daf082b7810 Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Thu, 3 Dec 2020 07:41:50 -0500 Subject: [PATCH] Clean up key handlers on activateExtension This fixes URL exceptions on sites with their own key handlers for me. Before, the keydown listener Vimari registers to stop propagation would still be set (apparently) --- Vimari Extension/js/injected.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Vimari Extension/js/injected.js b/Vimari Extension/js/injected.js index 02c3dfe..cd31e41 100644 --- a/Vimari Extension/js/injected.js +++ b/Vimari Extension/js/injected.js @@ -249,23 +249,21 @@ function boundKeys() { // Stops propagation of keyboard events in normal mode. Adding this // callback to the document using the useCapture flag allows us to // prevent custom key behaviour implemented by the underlying website. -function stopSitePropagation() { - return function (e) { - if (insertMode) { - // Never stop propagation in insert mode. - return - } +function stopSitePropagation(e) { + if (insertMode) { + // Never stop propagation in insert mode. + return + } - if (settings.transparentBindings === true) { - if (boundKeys().has(e.key) && !isActiveElementEditable()) { - // If we are in normal mode with transparentBindings enabled we - // should only stop propagation in an editable element or if the - // key is bound to a Vimari action. - e.stopPropagation() - } - } else if (!isActiveElementEditable()) { + if (settings.transparentBindings === true) { + if (boundKeys().has(e.key) && !isActiveElementEditable()) { + // If we are in normal mode with transparentBindings enabled we + // should only stop propagation in an editable element or if the + // key is bound to a Vimari action. e.stopPropagation() } + } else if (!isActiveElementEditable()) { + e.stopPropagation() } } @@ -355,8 +353,11 @@ function activateExtension(settings) { return; } + // Clear any existing events + unbindKeyCodes(); + // Stop keydown propagation - document.addEventListener("keydown", stopSitePropagation(), true); + document.addEventListener("keydown", stopSitePropagation, true); bindKeyCodesToActions(settings); }