From d4bef13f8416bf4372854a45aca0f34f927c8179 Mon Sep 17 00:00:00 2001 From: jgdhs27 Date: Sat, 3 Jan 2026 15:58:10 +0100 Subject: [PATCH] Extract delete command Refactor: extract delete and deletion-related commands (such as change) from the insert function into a new function named `deleteSelections` Testing: ``` yarn test ``` --- extensions/helix/package.json | 101 +++++------------- package.json | 11 ++ src/api/data/commands.yaml | 100 +++++++---------- src/commands/README.md | 100 +++++++++-------- src/commands/edit.ts | 58 ++++++---- src/commands/layouts/azerty.fr.md | 100 +++++++++-------- src/commands/layouts/qwerty.md | 100 +++++++++-------- src/commands/load-all.ts | 28 +++-- .../{edit-insert.md => edit-delete.md} | 0 test/suite/commands/edit-delete.test.ts | 79 ++++++++++++++ .../{edit-insert.test.ts => edit-delete.ts} | 0 11 files changed, 372 insertions(+), 305 deletions(-) rename test/suite/commands/{edit-insert.md => edit-delete.md} (100%) create mode 100644 test/suite/commands/edit-delete.test.ts rename test/suite/commands/{edit-insert.test.ts => edit-delete.ts} (100%) diff --git a/extensions/helix/package.json b/extensions/helix/package.json index 0777b918..fa59972a 100644 --- a/extensions/helix/package.json +++ b/extensions/helix/package.json @@ -1503,6 +1503,12 @@ "title": "Delete", "command": "dance.edit.delete" }, + { + "key": "D", + "when": "editorTextFocus && dance.mode == 'helix/normal'", + "title": "Delete contents of selection", + "command": "dance.edit.deleteSelections" + }, { "key": "Shift+.", "when": "editorTextFocus && dance.mode == 'helix/normal'", @@ -1599,81 +1605,6 @@ "title": "Copy, delete and switch to Insert", "command": "dance.edit.yank-delete-insert" }, - { - "key": "Shift+R", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "command": "dance.run", - "args": { - "commands": [ - [ - ".edit.insert" - ], - [ - ".modes.set.normal" - ] - ] - } - }, - { - "key": "Alt+D", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "command": "dance.run", - "args": { - "commands": [ - [ - ".edit.delete" - ], - [ - ".modes.set.normal" - ] - ] - } - }, - { - "key": "D", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "command": "dance.run", - "args": { - "commands": [ - [ - ".edit.yank-delete" - ], - [ - ".modes.set.normal" - ] - ] - } - }, - { - "key": "Shift+P", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "command": "dance.run", - "args": { - "commands": [ - [ - ".edit.paste.before" - ], - [ - ".modes.set.normal" - ] - ] - } - }, - { - "key": "P", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "command": "dance.run", - "args": { - "commands": [ - [ - ".edit.paste.after" - ], - [ - ".modes.set.normal" - ] - ] - } - }, { "key": "Shift+.", "when": "editorTextFocus && dance.mode == 'helix/select'", @@ -3340,6 +3271,16 @@ "command": "dance.ignore", "when": "editorTextFocus && dance.mode == 'helix/normal'" }, + { + "key": "D", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/select'" + }, + { + "key": "P", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/select'" + }, { "key": "Q", "command": "dance.ignore", @@ -3375,11 +3316,21 @@ "command": "dance.ignore", "when": "editorTextFocus && dance.mode == 'helix/select'" }, + { + "key": "Shift+P", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/select'" + }, { "key": "Shift+Q", "command": "dance.ignore", "when": "editorTextFocus && dance.mode == 'helix/select'" }, + { + "key": "Shift+R", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/select'" + }, { "key": "Shift+V", "command": "dance.ignore", diff --git a/package.json b/package.json index 42a7732e..8f76e28d 100644 --- a/package.json +++ b/package.json @@ -1025,6 +1025,11 @@ "title": "Delete and switch to Insert", "category": "Dance" }, + { + "command": "dance.edit.deleteSelections", + "title": "Delete contents of selection", + "category": "Dance" + }, { "command": "dance.edit.indent", "title": "Indent selected lines", @@ -2046,6 +2051,12 @@ "title": "Delete and switch to Insert", "command": "dance.edit.delete-insert" }, + { + "key": "D", + "when": "editorTextFocus && dance.mode == 'normal'", + "title": "Delete contents of selection", + "command": "dance.edit.deleteSelections" + }, { "key": "Shift+.", "when": "editorTextFocus && dance.mode == 'normal'", diff --git a/src/api/data/commands.yaml b/src/api/data/commands.yaml index 78398f68..47666fd6 100644 --- a/src/api/data/commands.yaml +++ b/src/api/data/commands.yaml @@ -155,7 +155,7 @@ edit.delete: en: Delete commands: |- - [".edit.insert", { register: "_", $exclude: [] }] + [".edit.deleteSelections"] keys: qwerty: |- @@ -166,12 +166,34 @@ edit.delete-insert: en: Delete and switch to Insert commands: |- - [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.insert", { register: "_", $exclude: ["mode"] }] + [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"] keys: qwerty: |- `a-c` (kakoune: normal) +edit.deleteSelections: + title: + en: Delete contents of selection + + keys: + qwerty: |- + `d` (core: normal) + + doc: + en: | + Delete contents of selection. + + + #### Additional commands + + | Title | Identifier | Keybinding | Commands | + | --------------------------------- | -------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------- | + | Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections"]` | + | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | + | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + edit.indent: title: en: Indent selected lines @@ -226,27 +248,18 @@ edit.insert: #### Additional commands - | Title | Identifier | Keybinding | Commands | - | ---------------------------------- | ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | - | Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | - | Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | - | Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | - | Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | - | Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | - | Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | - | Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | - | Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | - | Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | - | Delete | `delete` | `a-d` (core: normal) | `[".edit.insert", { register: "_", ... }]` | - | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | - | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.insert", { register: "_", ... }]` | - | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | - | Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | - | | | `s-r` (helix: select) | `[".edit.insert"], [".modes.set.normal"]` | - | | | `a-d` (helix: select) | `[".edit.delete"], [".modes.set.normal"]` | - | | | `d` (helix: select) | `[".edit.yank-delete"], [".modes.set.normal"]` | - | | | `s-p` (helix: select) | `[".edit.paste.before"], [".modes.set.normal"]` | - | | | `p` (helix: select) | `[".edit.paste.after"], [".modes.set.normal"]` | + | Title | Identifier | Keybinding | Commands | + | --------------------------- | ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | + | Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | + | Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | + | Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | + | Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | + | Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | + | Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | + | Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | + | Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | + | Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | + | Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | edit.join: title: @@ -441,10 +454,10 @@ edit.selectRegister-insert: edit.yank-delete: title: - en: "Copy and delete" + en: Copy and delete commands: |- - [".selections.saveText", { $include: ["register"] }], [".edit.insert", { register: "_", $exclude: ["register"] }] + [".selections.saveText", { $include: ["register"] }], [".edit.deleteSelections"] keys: qwerty: |- @@ -455,7 +468,7 @@ edit.yank-delete-insert: en: Copy, delete and switch to Insert commands: |- - [".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.insert", { register: "_", $exclude: ["register","mode"] }] + [".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"] keys: qwerty: |- @@ -2749,13 +2762,6 @@ anonymous: qwerty: |- `<` (helix: select) - - commands: |- - [".edit.delete"], [".modes.set.normal"] - - keys: - qwerty: |- - `a-d` (helix: select) - - commands: |- [".edit.indent"], [".modes.set.normal"] @@ -2763,27 +2769,6 @@ anonymous: qwerty: |- `>` (helix: select) - - commands: |- - [".edit.insert"], [".modes.set.normal"] - - keys: - qwerty: |- - `s-r` (helix: select) - - - commands: |- - [".edit.paste.after"], [".modes.set.normal"] - - keys: - qwerty: |- - `p` (helix: select) - - - commands: |- - [".edit.paste.before"], [".modes.set.normal"] - - keys: - qwerty: |- - `s-p` (helix: select) - - commands: |- [".edit.replaceCharacters"], [".modes.set.normal"] @@ -2791,13 +2776,6 @@ anonymous: qwerty: |- `r` (helix: select) - - commands: |- - [".edit.yank-delete"], [".modes.set.normal"] - - keys: - qwerty: |- - `d` (helix: select) - - title: en: Left bracket diff --git a/src/commands/README.md b/src/commands/README.md index 05e38c4e..f3f2bfc7 100644 --- a/src/commands/README.md +++ b/src/commands/README.md @@ -26,17 +26,18 @@ depending on the keyboard layout. The following layouts _will be_\* supported: devdev.copyLastErrorMessageCopies the last encountered error message dev.setSelectionBehaviorSet the selection behavior of the specified mode -editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') +editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') edit.case.swapSwap caseAlt+` (editorTextFocus && dance.mode == 'normal')Shift+` (editorTextFocus && dance.mode == 'normal') edit.case.toLowerTransform to lower case` (editorTextFocus && dance.mode == 'normal') edit.case.toUpperTransform to upper caseShift+` (editorTextFocus && dance.mode == 'normal')Alt+` (editorTextFocus && dance.mode == 'normal') edit.copyIndentationCopy indentationShift+Alt+7 (editorTextFocus && dance.mode == 'normal') edit.deindentDeindent selected linesShift+Alt+, (editorTextFocus && dance.mode == 'normal') edit.deindent.withIncompleteDeindent selected lines (including incomplete indent)Shift+, (editorTextFocus && dance.mode == 'normal') -edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') -edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') -edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') -edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') +edit.deleteSelectionsDelete contents of selectionD (editorTextFocus && dance.mode == 'normal') +edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') +edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') +edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') +edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') edit.paste.afterPaste after edit.paste.after.selectPaste after and selectP (editorTextFocus && dance.mode == 'normal') edit.paste.beforePaste before @@ -46,9 +47,9 @@ depending on the keyboard layout. The following layouts _will be_\* supported: edit.pasteAll.beforePaste all before edit.pasteAll.before.selectPaste all before and selectShift+Alt+P (editorTextFocus && dance.mode == 'normal') edit.selectRegister-insertPick register and replaceCtrl+R (editorTextFocus && dance.mode == 'normal')Ctrl+R (editorTextFocus && dance.mode == 'insert') -edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') -edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') -edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') +edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') +edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') +edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') edit.indentIndent selected linesShift+. (editorTextFocus && dance.mode == 'normal') edit.indent.withEmptyIndent selected lines (including empty lines)Shift+Alt+. (editorTextFocus && dance.mode == 'normal') edit.insertInsert contents of registerShift+Alt+R (editorTextFocus && dance.mode == 'normal')Shift+R (editorTextFocus && dance.mode == 'normal') @@ -265,7 +266,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](./edit.ts#L15-L66) +### [`edit.insert`](./edit.ts#L15-L57) Insert contents of register. @@ -282,27 +283,18 @@ Specify `all` to paste all contents next to each selection. #### Additional commands -| Title | Identifier | Keybinding | Commands | -| ---------------------------------- | ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | -| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | -| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | -| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | -| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | -| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | -| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | -| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | -| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | -| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | -| Delete | `delete` | `a-d` (core: normal) | `[".edit.insert", { register: "_", ... }]` | -| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.insert", { register: "_", ... }]` | -| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | -| | | `s-r` (helix: select) | `[".edit.insert"], [".modes.set.normal"]` | -| | | `a-d` (helix: select) | `[".edit.delete"], [".modes.set.normal"]` | -| | | `d` (helix: select) | `[".edit.yank-delete"], [".modes.set.normal"]` | -| | | `s-p` (helix: select) | `[".edit.paste.before"], [".modes.set.normal"]` | -| | | `p` (helix: select) | `[".edit.paste.after"], [".modes.set.normal"]` | +| Title | Identifier | Keybinding | Commands | +| --------------------------- | ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | +| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | +| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | +| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | +| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | +| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | +| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | +| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | +| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | +| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | +| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | This command: - accepts a register (by default, it uses `dquote`). @@ -311,15 +303,33 @@ This command: - takes an argument `all` of type `boolean`. - takes an argument `handleNewLine` of type `boolean`. - takes an argument `shift` of type `Shift`. -- takes an argument `text` of type `string`. - takes an argument `where` of type `"active" | "anchor" | "start" | "end" | undefined`. Default keybinding: `s-a-r` (kakoune: normal) `s-r` (helix: normal) + + +### [`edit.deleteSelections`](./edit.ts#L129-L146) + +Delete contents of selection. + + +#### Additional commands + +| Title | Identifier | Keybinding | Commands | +| --------------------------------- | -------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections"]` | +| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | +| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | +| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + + +Default keybinding: `d` (core: normal) + -### [`edit.join`](./edit.ts#L138-L143) +### [`edit.join`](./edit.ts#L150-L155) Join lines. @@ -332,7 +342,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](./edit.ts#L147-L152) +### [`edit.join.select`](./edit.ts#L159-L164) Join lines and select inserted separators. @@ -344,7 +354,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](./edit.ts#L156-L164) +### [`edit.indent`](./edit.ts#L168-L176) Indent selected lines. @@ -359,7 +369,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](./edit.ts#L168-L173) +### [`edit.indent.withEmpty`](./edit.ts#L180-L185) Indent selected lines (including empty lines). @@ -371,7 +381,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](./edit.ts#L177-L182) +### [`edit.deindent`](./edit.ts#L189-L194) Deindent selected lines. @@ -383,7 +393,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](./edit.ts#L186-L194) +### [`edit.deindent.withIncomplete`](./edit.ts#L198-L206) Deindent selected lines (including incomplete indent). @@ -398,7 +408,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](./edit.ts#L198-L206) +### [`edit.case.toLower`](./edit.ts#L210-L218) Transform to lower case. @@ -411,7 +421,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](./edit.ts#L210-L218) +### [`edit.case.toUpper`](./edit.ts#L222-L230) Transform to upper case. @@ -425,7 +435,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](./edit.ts#L222-L230) +### [`edit.case.swap`](./edit.ts#L234-L242) Swap case. @@ -439,7 +449,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](./edit.ts#L245-L257) +### [`edit.replaceCharacters`](./edit.ts#L257-L269) Replace characters. @@ -455,7 +465,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](./edit.ts#L300-L308) +### [`edit.align`](./edit.ts#L312-L320) Align selections. @@ -470,7 +480,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](./edit.ts#L358-L371) +### [`edit.copyIndentation`](./edit.ts#L370-L383) Copy indentation. @@ -485,7 +495,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](./edit.ts#L400-L418) +### [`edit.newLine.above`](./edit.ts#L412-L430) Insert new line above each selection. @@ -507,7 +517,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](./edit.ts#L438-L456) +### [`edit.newLine.below`](./edit.ts#L450-L468) Insert new line below each selection. diff --git a/src/commands/edit.ts b/src/commands/edit.ts index 693e78e9..35409fe2 100644 --- a/src/commands/edit.ts +++ b/src/commands/edit.ts @@ -29,27 +29,18 @@ declare module "./edit"; * * #### Additional commands * - * | Title | Identifier | Keybinding | Commands | - * | ---------------------------------- | ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | - * | Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | - * | Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | - * | Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | - * | Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | - * | Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | - * | Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | - * | Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | - * | Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | - * | Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | - * | Delete | `delete` | `a-d` (core: normal) | `[".edit.insert", { register: "_", ... }]` | - * | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | - * | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.insert", { register: "_", ... }]` | - * | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | - * | Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | - * | | | `s-r` (helix: select) | `[".edit.insert"], [".modes.set.normal"]` | - * | | | `a-d` (helix: select) | `[".edit.delete"], [".modes.set.normal"]` | - * | | | `d` (helix: select) | `[".edit.yank-delete"], [".modes.set.normal"]` | - * | | | `s-p` (helix: select) | `[".edit.paste.before"], [".modes.set.normal"]` | - * | | | `p` (helix: select) | `[".edit.paste.after"], [".modes.set.normal"]` | + * | Title | Identifier | Keybinding | Commands | + * | --------------------------- | ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | + * | Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | + * | Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | + * | Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | + * | Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | + * | Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | + * | Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | + * | Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | + * | Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | + * | Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | + * | Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | */ export async function insert( _: Context, @@ -60,9 +51,9 @@ export async function insert( all: Argument = false, handleNewLine: Argument = false, repetitions: number, - shift?: Argument, - text?: Argument, + text: Argument, where?: Argument<"active" | "anchor" | "start" | "end" | undefined>, + shift?: Argument, ) { let contents = text?.length ? (shift === Shift.Select ? [text] : selections.map(() => text)) @@ -135,6 +126,27 @@ export async function insert( ); } +/** + * Delete contents of selection. + * + * @keys `d` (core: normal) + * + * #### Additional commands + * + * | Title | Identifier | Keybinding | Commands | + * | --------------------------------- | -------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------- | + * | Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections"]` | + * | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + * | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | + * | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + */ +export async function deleteSelections( + _: Context, + selections: readonly vscode.Selection[], +) { + Selections.set(await replace((_) => "", selections)); +} + /** * Join lines. * diff --git a/src/commands/layouts/azerty.fr.md b/src/commands/layouts/azerty.fr.md index c9ad209e..030e6be7 100644 --- a/src/commands/layouts/azerty.fr.md +++ b/src/commands/layouts/azerty.fr.md @@ -11,17 +11,18 @@ devdev.copyLastErrorMessageCopies the last encountered error message dev.setSelectionBehaviorSet the selection behavior of the specified mode -editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') +editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') edit.case.swapSwap caseAlt+` (editorTextFocus && dance.mode == 'normal')Shift+` (editorTextFocus && dance.mode == 'normal') edit.case.toLowerTransform to lower case` (editorTextFocus && dance.mode == 'normal') edit.case.toUpperTransform to upper caseShift+` (editorTextFocus && dance.mode == 'normal')Alt+` (editorTextFocus && dance.mode == 'normal') edit.copyIndentationCopy indentationShift+Alt+7 (editorTextFocus && dance.mode == 'normal') edit.deindentDeindent selected linesShift+Alt+, (editorTextFocus && dance.mode == 'normal') edit.deindent.withIncompleteDeindent selected lines (including incomplete indent)Shift+, (editorTextFocus && dance.mode == 'normal') -edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') -edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') -edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') -edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') +edit.deleteSelectionsDelete contents of selectionD (editorTextFocus && dance.mode == 'normal') +edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') +edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') +edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') +edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') edit.paste.afterPaste after edit.paste.after.selectPaste after and selectP (editorTextFocus && dance.mode == 'normal') edit.paste.beforePaste before @@ -31,9 +32,9 @@ edit.pasteAll.beforePaste all before edit.pasteAll.before.selectPaste all before and selectShift+Alt+P (editorTextFocus && dance.mode == 'normal') edit.selectRegister-insertPick register and replaceCtrl+R (editorTextFocus && dance.mode == 'normal')Ctrl+R (editorTextFocus && dance.mode == 'insert') -edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') -edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') -edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') +edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') +edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') +edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') edit.indentIndent selected linesShift+. (editorTextFocus && dance.mode == 'normal') edit.indent.withEmptyIndent selected lines (including empty lines)Shift+Alt+. (editorTextFocus && dance.mode == 'normal') edit.insertInsert contents of registerShift+Alt+R (editorTextFocus && dance.mode == 'normal')Shift+R (editorTextFocus && dance.mode == 'normal') @@ -250,7 +251,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](../edit.ts#L15-L66) +### [`edit.insert`](../edit.ts#L15-L57) Insert contents of register. @@ -267,27 +268,18 @@ Specify `all` to paste all contents next to each selection. #### Additional commands -| Title | Identifier | Keybinding | Commands | -| ---------------------------------- | ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | -| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | -| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | -| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | -| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | -| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | -| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | -| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | -| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | -| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | -| Delete | `delete` | `a-d` (core: normal) | `[".edit.insert", { register: "_", ... }]` | -| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.insert", { register: "_", ... }]` | -| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | -| | | `s-r` (helix: select) | `[".edit.insert"], [".modes.set.normal"]` | -| | | `a-d` (helix: select) | `[".edit.delete"], [".modes.set.normal"]` | -| | | `d` (helix: select) | `[".edit.yank-delete"], [".modes.set.normal"]` | -| | | `s-p` (helix: select) | `[".edit.paste.before"], [".modes.set.normal"]` | -| | | `p` (helix: select) | `[".edit.paste.after"], [".modes.set.normal"]` | +| Title | Identifier | Keybinding | Commands | +| --------------------------- | ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | +| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | +| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | +| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | +| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | +| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | +| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | +| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | +| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | +| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | +| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | This command: - accepts a register (by default, it uses `dquote`). @@ -296,15 +288,33 @@ This command: - takes an argument `all` of type `boolean`. - takes an argument `handleNewLine` of type `boolean`. - takes an argument `shift` of type `Shift`. -- takes an argument `text` of type `string`. - takes an argument `where` of type `"active" | "anchor" | "start" | "end" | undefined`. Default keybinding: `s-a-r` (kakoune: normal) `s-r` (helix: normal) + + +### [`edit.deleteSelections`](../edit.ts#L129-L146) + +Delete contents of selection. + + +#### Additional commands + +| Title | Identifier | Keybinding | Commands | +| --------------------------------- | -------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections"]` | +| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | +| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | +| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + + +Default keybinding: `d` (core: normal) + -### [`edit.join`](../edit.ts#L138-L143) +### [`edit.join`](../edit.ts#L150-L155) Join lines. @@ -317,7 +327,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](../edit.ts#L147-L152) +### [`edit.join.select`](../edit.ts#L159-L164) Join lines and select inserted separators. @@ -329,7 +339,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](../edit.ts#L156-L164) +### [`edit.indent`](../edit.ts#L168-L176) Indent selected lines. @@ -344,7 +354,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](../edit.ts#L168-L173) +### [`edit.indent.withEmpty`](../edit.ts#L180-L185) Indent selected lines (including empty lines). @@ -356,7 +366,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](../edit.ts#L177-L182) +### [`edit.deindent`](../edit.ts#L189-L194) Deindent selected lines. @@ -368,7 +378,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](../edit.ts#L186-L194) +### [`edit.deindent.withIncomplete`](../edit.ts#L198-L206) Deindent selected lines (including incomplete indent). @@ -383,7 +393,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](../edit.ts#L198-L206) +### [`edit.case.toLower`](../edit.ts#L210-L218) Transform to lower case. @@ -396,7 +406,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](../edit.ts#L210-L218) +### [`edit.case.toUpper`](../edit.ts#L222-L230) Transform to upper case. @@ -410,7 +420,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](../edit.ts#L222-L230) +### [`edit.case.swap`](../edit.ts#L234-L242) Swap case. @@ -424,7 +434,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](../edit.ts#L245-L257) +### [`edit.replaceCharacters`](../edit.ts#L257-L269) Replace characters. @@ -440,7 +450,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](../edit.ts#L300-L308) +### [`edit.align`](../edit.ts#L312-L320) Align selections. @@ -455,7 +465,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](../edit.ts#L358-L371) +### [`edit.copyIndentation`](../edit.ts#L370-L383) Copy indentation. @@ -470,7 +480,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](../edit.ts#L400-L418) +### [`edit.newLine.above`](../edit.ts#L412-L430) Insert new line above each selection. @@ -492,7 +502,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](../edit.ts#L438-L456) +### [`edit.newLine.below`](../edit.ts#L450-L468) Insert new line below each selection. diff --git a/src/commands/layouts/qwerty.md b/src/commands/layouts/qwerty.md index f79f5744..13d931e7 100644 --- a/src/commands/layouts/qwerty.md +++ b/src/commands/layouts/qwerty.md @@ -11,17 +11,18 @@ devdev.copyLastErrorMessageCopies the last encountered error message dev.setSelectionBehaviorSet the selection behavior of the specified mode -editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') +editedit.alignAlign selectionsShift+7 (editorTextFocus && dance.mode == 'normal') edit.case.swapSwap caseAlt+` (editorTextFocus && dance.mode == 'normal')Shift+` (editorTextFocus && dance.mode == 'normal') edit.case.toLowerTransform to lower case` (editorTextFocus && dance.mode == 'normal') edit.case.toUpperTransform to upper caseShift+` (editorTextFocus && dance.mode == 'normal')Alt+` (editorTextFocus && dance.mode == 'normal') edit.copyIndentationCopy indentationShift+Alt+7 (editorTextFocus && dance.mode == 'normal') edit.deindentDeindent selected linesShift+Alt+, (editorTextFocus && dance.mode == 'normal') edit.deindent.withIncompleteDeindent selected lines (including incomplete indent)Shift+, (editorTextFocus && dance.mode == 'normal') -edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') -edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') -edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') -edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') +edit.deleteSelectionsDelete contents of selectionD (editorTextFocus && dance.mode == 'normal') +edit.deleteDeleteAlt+D (editorTextFocus && dance.mode == 'normal') +edit.delete-insertDelete and switch to InsertAlt+C (editorTextFocus && dance.mode == 'normal') +edit.newLine.above.insertInsert new line above and switch to insertShift+O (editorTextFocus && dance.mode == 'normal')Shift+O (editorTextFocus && dance.mode == 'select') +edit.newLine.below.insertInsert new line below and switch to insertO (editorTextFocus && dance.mode == 'normal')O (editorTextFocus && dance.mode == 'select') edit.paste.afterPaste after edit.paste.after.selectPaste after and selectP (editorTextFocus && dance.mode == 'normal') edit.paste.beforePaste before @@ -31,9 +32,9 @@ edit.pasteAll.beforePaste all before edit.pasteAll.before.selectPaste all before and selectShift+Alt+P (editorTextFocus && dance.mode == 'normal') edit.selectRegister-insertPick register and replaceCtrl+R (editorTextFocus && dance.mode == 'normal')Ctrl+R (editorTextFocus && dance.mode == 'insert') -edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') -edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') -edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') +edit.yank-deleteCopy and deleteD (editorTextFocus && dance.mode == 'normal') +edit.yank-delete-insertCopy, delete and switch to InsertC (editorTextFocus && dance.mode == 'normal')C (editorTextFocus && dance.mode == 'select') +edit.yank-replaceCopy and replaceShift+R (editorTextFocus && dance.mode == 'normal') edit.indentIndent selected linesShift+. (editorTextFocus && dance.mode == 'normal') edit.indent.withEmptyIndent selected lines (including empty lines)Shift+Alt+. (editorTextFocus && dance.mode == 'normal') edit.insertInsert contents of registerShift+Alt+R (editorTextFocus && dance.mode == 'normal')Shift+R (editorTextFocus && dance.mode == 'normal') @@ -250,7 +251,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](../edit.ts#L15-L66) +### [`edit.insert`](../edit.ts#L15-L57) Insert contents of register. @@ -267,27 +268,18 @@ Specify `all` to paste all contents next to each selection. #### Additional commands -| Title | Identifier | Keybinding | Commands | -| ---------------------------------- | ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | -| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | -| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | -| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | -| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | -| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | -| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | -| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | -| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | -| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | -| Delete | `delete` | `a-d` (core: normal) | `[".edit.insert", { register: "_", ... }]` | -| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.insert", { register: "_", ... }]` | -| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.insert", { register: "_", ... }]` | -| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | -| | | `s-r` (helix: select) | `[".edit.insert"], [".modes.set.normal"]` | -| | | `a-d` (helix: select) | `[".edit.delete"], [".modes.set.normal"]` | -| | | `d` (helix: select) | `[".edit.yank-delete"], [".modes.set.normal"]` | -| | | `s-p` (helix: select) | `[".edit.paste.before"], [".modes.set.normal"]` | -| | | `p` (helix: select) | `[".edit.paste.after"], [".modes.set.normal"]` | +| Title | Identifier | Keybinding | Commands | +| --------------------------- | ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | +| Pick register and replace | `selectRegister-insert` | `c-r` (kakoune: normal), `c-r` (kakoune: insert) | `[".selectRegister", { +register }], [".edit.insert", { ... }]` | +| Paste before | `paste.before` | | `[".edit.insert", { handleNewLine: true, where: "start", ... }]` | +| Paste after | `paste.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , ... }]` | +| Paste before and select | `paste.before.select` | `s-p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "start", shift: "select", ... }]` | +| Paste after and select | `paste.after.select` | `p` (core: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , shift: "select", ... }]` | +| Paste all before | `pasteAll.before` | | `[".edit.insert", { handleNewLine: true, where: "start", all: true, ... }]` | +| Paste all after | `pasteAll.after` | | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, ... }]` | +| Paste all before and select | `pasteAll.before.select` | `s-a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "start", all: true, shift: "select", ... }]` | +| Paste all after and select | `pasteAll.after.select` | `a-p` (kakoune: normal) | `[".edit.insert", { handleNewLine: true, where: "end" , all: true, shift: "select", ... }]` | +| Copy and replace | `yank-replace` | `s-r` (kakoune: normal) | `[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", ... }]` | This command: - accepts a register (by default, it uses `dquote`). @@ -296,15 +288,33 @@ This command: - takes an argument `all` of type `boolean`. - takes an argument `handleNewLine` of type `boolean`. - takes an argument `shift` of type `Shift`. -- takes an argument `text` of type `string`. - takes an argument `where` of type `"active" | "anchor" | "start" | "end" | undefined`. Default keybinding: `s-a-r` (kakoune: normal) `s-r` (helix: normal) + + +### [`edit.deleteSelections`](../edit.ts#L129-L146) + +Delete contents of selection. + + +#### Additional commands + +| Title | Identifier | Keybinding | Commands | +| --------------------------------- | -------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections"]` | +| Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | +| Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | +| Copy, delete and switch to Insert | `yank-delete-insert` | `c` (core: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + + +Default keybinding: `d` (core: normal) + -### [`edit.join`](../edit.ts#L138-L143) +### [`edit.join`](../edit.ts#L150-L155) Join lines. @@ -317,7 +327,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](../edit.ts#L147-L152) +### [`edit.join.select`](../edit.ts#L159-L164) Join lines and select inserted separators. @@ -329,7 +339,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](../edit.ts#L156-L164) +### [`edit.indent`](../edit.ts#L168-L176) Indent selected lines. @@ -344,7 +354,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](../edit.ts#L168-L173) +### [`edit.indent.withEmpty`](../edit.ts#L180-L185) Indent selected lines (including empty lines). @@ -356,7 +366,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](../edit.ts#L177-L182) +### [`edit.deindent`](../edit.ts#L189-L194) Deindent selected lines. @@ -368,7 +378,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](../edit.ts#L186-L194) +### [`edit.deindent.withIncomplete`](../edit.ts#L198-L206) Deindent selected lines (including incomplete indent). @@ -383,7 +393,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](../edit.ts#L198-L206) +### [`edit.case.toLower`](../edit.ts#L210-L218) Transform to lower case. @@ -396,7 +406,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](../edit.ts#L210-L218) +### [`edit.case.toUpper`](../edit.ts#L222-L230) Transform to upper case. @@ -410,7 +420,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](../edit.ts#L222-L230) +### [`edit.case.swap`](../edit.ts#L234-L242) Swap case. @@ -424,7 +434,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](../edit.ts#L245-L257) +### [`edit.replaceCharacters`](../edit.ts#L257-L269) Replace characters. @@ -440,7 +450,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](../edit.ts#L300-L308) +### [`edit.align`](../edit.ts#L312-L320) Align selections. @@ -455,7 +465,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](../edit.ts#L358-L371) +### [`edit.copyIndentation`](../edit.ts#L370-L383) Copy indentation. @@ -470,7 +480,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](../edit.ts#L400-L418) +### [`edit.newLine.above`](../edit.ts#L412-L430) Insert new line above each selection. @@ -492,7 +502,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](../edit.ts#L438-L456) +### [`edit.newLine.below`](../edit.ts#L450-L468) Insert new line below each selection. diff --git a/src/commands/load-all.ts b/src/commands/load-all.ts index 11eec322..30c60e18 100644 --- a/src/commands/load-all.ts +++ b/src/commands/load-all.ts @@ -162,6 +162,7 @@ import { copyIndentation as edit_copyIndentation, deindent as edit_deindent, deindent_withIncomplete as edit_deindent_withIncomplete, + deleteSelections as edit_deleteSelections, indent as edit_indent, indent_withEmpty as edit_indent_withEmpty, insert as edit_insert, @@ -334,6 +335,11 @@ export const commands: Commands = function () { (_, argument) => _.runAsync(async (_) => await edit_deindent_withIncomplete(_, getRepetitions(_, argument))), CommandDescriptor.Flags.RequiresActiveEditor, ), + "dance.edit.deleteSelections": new CommandDescriptor( + "dance.edit.deleteSelections", + (_) => _.runAsync(async (_) => await edit_deleteSelections(_, _.selections)), + CommandDescriptor.Flags.RequiresActiveEditor, + ), "dance.edit.indent": new CommandDescriptor( "dance.edit.indent", (_, argument) => _.runAsync(async (_) => await edit_indent(_, getRepetitions(_, argument))), @@ -346,7 +352,7 @@ export const commands: Commands = function () { ), "dance.edit.insert": new CommandDescriptor( "dance.edit.insert", - (_, argument) => _.runAsync(async (_) => await edit_insert(_, _.selections, getRegister(_, argument, "dquote", Register.Flags.CanRead), argument["adjust"], argument["all"], argument["handleNewLine"], getRepetitions(_, argument), getShift(argument), argument["text"], argument["where"])), + (_, argument) => _.runAsync(async (_) => await edit_insert(_, _.selections, getRegister(_, argument, "dquote", Register.Flags.CanRead), argument["adjust"], argument["all"], argument["handleNewLine"], getRepetitions(_, argument), argument["text"], argument["where"], getShift(argument))), CommandDescriptor.Flags.RequiresActiveEditor, ), "dance.edit.join": new CommandDescriptor( @@ -778,33 +784,33 @@ export const commands: Commands = function () { ); describeAdditionalCommand( commands, - "dance.edit.delete", + "dance.edit.yank-replace", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".edit.insert", { register: "_", $exclude: [] }]], + [[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", $exclude: [] }]], ); describeAdditionalCommand( commands, - "dance.edit.delete-insert", + "dance.edit.delete", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.insert", { register: "_", $exclude: ["mode"] }]], + [[".edit.deleteSelections"]], ); describeAdditionalCommand( commands, - "dance.edit.yank-delete", + "dance.edit.delete-insert", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".selections.saveText", { $include: ["register"] }], [".edit.insert", { register: "_", $exclude: ["register"] }]], + [[".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"]], ); describeAdditionalCommand( commands, - "dance.edit.yank-delete-insert", + "dance.edit.yank-delete", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.insert", { register: "_", $exclude: ["register","mode"] }]], + [[".selections.saveText", { $include: ["register"] }], [".edit.deleteSelections"]], ); describeAdditionalCommand( commands, - "dance.edit.yank-replace", + "dance.edit.yank-delete-insert", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".selections.saveText", { register: "tmp" }], [".edit.insert"], [".updateRegister", { copyFrom: "tmp", $exclude: [] }]], + [[".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"]], ); describeAdditionalCommand( commands, diff --git a/test/suite/commands/edit-insert.md b/test/suite/commands/edit-delete.md similarity index 100% rename from test/suite/commands/edit-insert.md rename to test/suite/commands/edit-delete.md diff --git a/test/suite/commands/edit-delete.test.ts b/test/suite/commands/edit-delete.test.ts new file mode 100644 index 00000000..261ad044 --- /dev/null +++ b/test/suite/commands/edit-delete.test.ts @@ -0,0 +1,79 @@ +import * as vscode from "vscode"; + +import { executeCommand, ExpectedDocument, groupTestsByParentName } from "../utils"; + +suite("./test/suite/commands/edit-delete.md", function () { + // Set up document. + let document: vscode.TextDocument, + editor: vscode.TextEditor; + + this.beforeAll(async () => { + document = await vscode.workspace.openTextDocument({ language: "plaintext" }); + editor = await vscode.window.showTextDocument(document); + editor.options.insertSpaces = true; + editor.options.tabSize = 2; + + await executeCommand("dance.dev.setSelectionBehavior", { mode: "normal", value: "caret" }); + }); + + this.afterAll(async () => { + await executeCommand("workbench.action.closeActiveEditor"); + }); + + test("1 > delete", async function () { + // Set-up document to be in expected initial state. + await ExpectedDocument.apply(editor, 6, String.raw` + foo bar + ^^ 0 + `); + + // Perform all operations. + await executeCommand("dance.edit.delete"); + + // Ensure document is as expected. + ExpectedDocument.assertEquals(editor, "./test/suite/commands/edit-delete.md:8:1", 6, String.raw` + fooar + | 0 + `); + }); + + test("1 > delete-character", async function () { + // Set-up document to be in expected initial state. + await ExpectedDocument.apply(editor, 6, String.raw` + foo bar + ^^ 0 + `); + + // Perform all operations. + await executeCommand("dance.dev.setSelectionBehavior", { mode: "normal", value: "character" }); + await executeCommand("dance.edit.delete"); + await executeCommand("dance.dev.setSelectionBehavior", { mode: "normal", value: "caret" }); + + // Ensure document is as expected. + ExpectedDocument.assertEquals(editor, "./test/suite/commands/edit-delete.md:18:1", 6, String.raw` + fooar + ^ 0 + `); + }); + + test("1 > delete-character > x", async function () { + // Set-up document to be in expected initial state. + await ExpectedDocument.apply(editor, 6, String.raw` + fooar + ^ 0 + `); + + // Perform all operations. + await executeCommand("dance.dev.setSelectionBehavior", { mode: "normal", value: "character" }); + await executeCommand("dance.edit.delete"); + await executeCommand("dance.dev.setSelectionBehavior", { mode: "normal", value: "caret" }); + + // Ensure document is as expected. + ExpectedDocument.assertEquals(editor, "./test/suite/commands/edit-delete.md:30:1", 6, String.raw` + foor + ^ 0 + `); + }); + + groupTestsByParentName(this); +}); diff --git a/test/suite/commands/edit-insert.test.ts b/test/suite/commands/edit-delete.ts similarity index 100% rename from test/suite/commands/edit-insert.test.ts rename to test/suite/commands/edit-delete.ts