From a5984e113d130d4590252e01c59b54519812bb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20L=C3=BCker?= Date: Sat, 27 Aug 2022 13:16:31 +0200 Subject: [PATCH] added support for visual mode --- meta.ts | 1 + package.build.ts | 20 ++++++++++++++++++-- src/commands/modes.ts | 23 +++++++++++++---------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/meta.ts b/meta.ts index f475ccd..58ebf03 100644 --- a/meta.ts +++ b/meta.ts @@ -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; diff --git a/package.build.ts b/package.build.ts index 25aabbe..f2b9e14 100644 --- a/package.build.ts +++ b/package.build.ts @@ -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; })(), diff --git a/src/commands/modes.ts b/src/commands/modes.ts index 42a9fc7..eda4b3a 100644 --- a/src/commands/modes.ts +++ b/src/commands/modes.ts @@ -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 */