mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Merge pull request #2052 from tridactyl/visual
Fix #2050: add WIP visual mode
This commit is contained in:
commit
23829ff415
4 changed files with 49 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -8,6 +8,7 @@ export type ModeName =
|
|||
| "ignore"
|
||||
| "gobble"
|
||||
| "input"
|
||||
| "visual"
|
||||
|
||||
export class PrevInput {
|
||||
inputId: string
|
||||
|
|
|
@ -135,10 +135,18 @@ export class default_config {
|
|||
*
|
||||
* They consist of key sequences mapped to ex commands.
|
||||
*/
|
||||
inputmaps = mergeDeep(this.imaps, {
|
||||
inputmaps = {
|
||||
"<Tab>": "focusinput -n",
|
||||
"<S-Tab>": "focusinput -N",
|
||||
})
|
||||
/**
|
||||
* Config objects with this key inherit their keys from the object specified.
|
||||
*
|
||||
* Only supports "root" objects. Subconfigs (`seturl`) work as expected.
|
||||
*
|
||||
* Here, this means that input mode is the same as insert mode except it has added binds for tab and shift-tab.
|
||||
*/
|
||||
"🕷🕷INHERITS🕷🕷": "imaps",
|
||||
}
|
||||
|
||||
/**
|
||||
* nmaps contain all of the bindings for "normal mode".
|
||||
|
@ -302,6 +310,23 @@ export class default_config {
|
|||
"open https://www.youtube.com/watch?v=M3iOROuTuMA",
|
||||
}
|
||||
|
||||
vmaps = {
|
||||
"<Escape>": "composite js document.getSelection().empty(); mode normal; hidecmdline",
|
||||
"<C-[>": "composite js document.getSelection().empty(); mode normal ; hidecmdline",
|
||||
"y": "composite js document.getSelection().toString() | clipboard yank",
|
||||
"l": 'js document.getSelection().modify("extend","forward","character")',
|
||||
"h": 'js document.getSelection().modify("extend","backward","character")',
|
||||
"e": 'js document.getSelection().modify("extend","forward","word")',
|
||||
"w": 'js document.getSelection().modify("extend","forward","word"); document.getSelection().modify("extend","forward","character")',
|
||||
"b": 'js document.getSelection().modify("extend","backward","word"); document.getSelection().modify("extend",forward","character")',
|
||||
"j": 'js document.getSelection().modify("extend","forward","line")',
|
||||
// "j": 'js document.getSelection().modify("extend","forward","paragraph")', // not implemented in Firefox
|
||||
"k": 'js document.getSelection().modify("extend","backward","line")',
|
||||
"$": 'js document.getSelection().modify("extend","forward","lineboundary")',
|
||||
"0": 'js document.getSelection().modify("extend","backward","lineboundary")',
|
||||
"🕷🕷INHERITS🕷🕷": "nmaps",
|
||||
}
|
||||
|
||||
hintmaps = {
|
||||
"<Backspace>": "hint.popKey",
|
||||
"<Escape>": "hint.reset",
|
||||
|
@ -968,9 +993,18 @@ const DEFAULTS = o(new default_config())
|
|||
*/
|
||||
function getDeepProperty(obj, target: string[]) {
|
||||
if (obj !== undefined && target.length) {
|
||||
return getDeepProperty(obj[target[0]], target.slice(1))
|
||||
if (obj["🕷🕷INHERITS🕷🕷"] === undefined) {
|
||||
return getDeepProperty(obj[target[0]], target.slice(1))
|
||||
} else {
|
||||
return getDeepProperty(mergeDeep(get(obj["🕷🕷INHERITS🕷🕷"]), obj)[target[0]], target.slice(1))
|
||||
}
|
||||
} else {
|
||||
return obj
|
||||
if (obj === undefined) return obj
|
||||
if (obj["🕷🕷INHERITS🕷🕷"] !== undefined) {
|
||||
return mergeDeep(get(obj["🕷🕷INHERITS🕷🕷"]), obj)
|
||||
} else {
|
||||
return obj
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue