added support for visual mode

This commit is contained in:
Leo Lüker 2022-08-27 13:16:31 +02:00
parent 7d73bfc024
commit a5984e113d
3 changed files with 32 additions and 12 deletions

View File

@ -508,6 +508,7 @@ export function parseKeys(keys: string) {
switch (tag) {
case "normal":
case "insert":
case "visual":
case "input":
whenClauses.push(`dance.mode ${negate ? "!=" : "=="} '${tag}'`);
break;

View File

@ -310,6 +310,8 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
}],
],
},
visual: {
},
normal: {
lineNumbers: "relative",
decorations: {
@ -725,17 +727,31 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
...symbols.map((x) => `Shift+${x}`),
]);
const normalKeys = keysToAssign;
const visualKeys = keysToAssign;
for (const keybinding of keybindings) {
keysToAssign.delete(keybinding.key);
if (keybinding.when.includes("normal")) {
normalKeys.delete(keybinding.key);
}
if (keybinding.when.includes("visual")) {
visualKeys.delete(keybinding.key);
}
}
for (const keyToAssign of keysToAssign) {
for (const keyToAssign of normalKeys) {
keybindings.push({
command: "dance.ignore",
key: keyToAssign,
when: "editorTextFocus && dance.mode == 'normal'",
});
}
for (const keyToAssign of visualKeys) {
keybindings.push({
command: "dance.ignore",
key: keyToAssign,
when: "editorTextFocus && dance.mode == 'visual'",
});
}
return keybindings;
})(),

View File

@ -11,19 +11,22 @@ declare module "./modes";
*
* #### Variants
*
* | Title | Identifier | Keybinding | Command |
* | ------------------ | ------------ | -------------------------- | ----------------------------------------------------------- |
* | Set mode to Normal | `set.normal` | `escape` (kakoune: insert) | `[".modes.set", { mode: "normal" }], ["hideSuggestWidget"]` |
* | Set mode to Insert | `set.insert` | | `[".modes.set", { mode: "insert" }]` |
* | Title | Identifier | Keybinding | Command |
* | ------------------ | ------------ | ------------------------ | ----------------------------------------------------------- |
* | Set mode to Normal | `set.normal` | `escape` (helix: insert) | `[".modes.set", { mode: "normal" }], ["hideSuggestWidget"]` |
* | Set mode to Insert | `set.insert` | | `[".modes.set", { mode: "insert" }]` |
* | Set mode to Normal | `set.normal` | `escape` (helix: visual) | `[".modes.set", { mode: "normal" }], ["hideSuggestWidget"]` |
* | Set mode to Visual | `set.visual` | | `[".modes.set", { mode: "visual" }]` |
*
* Other variants are provided to switch to insert mode:
*
* | Title | Identifier | Keybinding | Commands |
* | -------------------- | ------------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* | Insert before | `insert.before` | `i` (kakoune: normal) | `[".selections.faceBackward", { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert after | `insert.after` | `a` (kakoune: normal) | `[".selections.faceForward" , { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
* | Insert at line start | `insert.lineStart` | `s-i` (kakoune: normal) | `[".select.lineStart", { shift: "jump", skipBlank: true }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert at line end | `insert.lineEnd` | `s-a` (kakoune: normal) | `[".select.lineEnd" , { shift: "jump" }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
* | Title | Identifier | Keybinding | Commands |
* | -------------------- | ------------------ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* | Visual | `visual` | `v` (helix: normal) | `[".selections.faceBackward", { record: false }], [".modes.set", { mode: "visual", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert before | `insert.before` | `i` (helix: normal) | `[".selections.faceBackward", { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert after | `insert.after` | `a` (helix: normal) | `[".selections.faceForward" , { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
* | Insert at line start | `insert.lineStart` | `s-i` (helix: normal) | `[".select.lineStart", { shift: "jump", skipBlank: true }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert at line end | `insert.lineEnd` | `s-a` (helix: normal) | `[".select.lineEnd" , { shift: "jump" }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
*
* @noreplay
*/