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

Transparent Normal Mode #194

Merged
merged 8 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
33 changes: 31 additions & 2 deletions Vimari Extension/js/injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,41 @@ function unbindKeyCodes() {
document.removeEventListener("keydown", stopSitePropagation);
}

// Stops propagation of keyboard events in normal mode. Adding this
// Returns all keys bound in the settings.
function boundKeys() {
var bindings = Object.values(settings.bindings)
// Split multi-key bindings.
.flatMap(s => s.split(/\+| /i))

// Manually add the modifier, i, esc, and ctr+[.
bindings.push(settings.modifier)
bindings.push("i")
bindings.push("Escape")
bindings.push("Control")
bindings.push("[")

// Use a set to remove duplicates.
return new Set(bindings)
}

// 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 == false && !isActiveElementEditable()) {
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()) {
e.stopPropagation()
}
}
Expand Down
1 change: 1 addition & 0 deletions Vimari Extension/json/defaultSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"modifier": "",
"smoothScroll": true,
"scrollDuration": 25,
"transparentBindings": true,
"bindings": {
"hintToggle": "f",
"newTabHintToggle": "shift+f",
Expand Down