Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up key handlers on activateExtension #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Vimari Extension/js/injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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);
}

Expand Down