Fix #2050: add WIP visual mode

We need to make merging of nmaps happen at runtime
before we merge this, or we'll break the binds of
people who are just selecting text to help them
read.
This commit is contained in:
Oliver Blanthorn 2019-12-19 11:32:37 +00:00
parent d8c94c5a27
commit fec145606b
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
4 changed files with 17 additions and 0 deletions

View file

@ -355,6 +355,15 @@ config.getAsync("leavegithubalone").then(v => {
}
})
document.addEventListener("selectionchange", () => {
const selection = document.getSelection()
if (selection.anchorOffset == selection.focusOffset) {
contentState.mode = "normal"
} else {
contentState.mode = "visual"
}
})
// Listen for statistics from each content script and send them to the
// background for collection. Attach the observer to the window object
// since there's apparently a bug that causes performance observers to

View file

@ -101,6 +101,7 @@ function* ParserController() {
ignore: keys => generic.parser("ignoremaps", keys),
hint: hinting.parser,
gobble: gobblemode.parser,
visual: keys => generic.parser("vmaps", keys),
}
while (true) {

View file

@ -8,6 +8,7 @@ export type ModeName =
| "ignore"
| "gobble"
| "input"
| "visual"
export class PrevInput {
inputId: string

View file

@ -302,6 +302,12 @@ export class default_config {
"open https://www.youtube.com/watch?v=M3iOROuTuMA",
}
vmaps = mergeDeep(this.nmaps, { // we really want a real-time merge as this means that user normal binds will no longer work while text is selected
"<Escape>": "composite js document.getSelection().empty(); mode normal; hidecmdline",
"<C-[>": "composite js document.getSelection().empty(); mode normal ; hidecmdline",
"y": "composite js document.getSelection().toString() | yank",
})
hintmaps = {
"<Backspace>": "hint.popKey",
"<Escape>": "hint.reset",