From 108e55efe017e23bcb3769a866dc83fa8df87a19 Mon Sep 17 00:00:00 2001 From: jgdhs27 Date: Sat, 3 Jan 2026 15:58:10 +0100 Subject: [PATCH 1/2] 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 ``` TODO separate tests for deletion too --- 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 +++++---- 8 files changed, 293 insertions(+), 305 deletions(-) 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..4defc02e 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..9d77efe0 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..470689cc 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..e664d6c1 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..2a0dbae0 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, From b61848c898528db7bb798071778658403f859c37 Mon Sep 17 00:00:00 2001 From: jgdhs27 Date: Sat, 17 Jan 2026 15:18:16 +0000 Subject: [PATCH 2/2] Change while preserving lines Introduce new commands to delete while preserving lines, similar to how it is done in Helix. Before this change, running `xc` in helix would delete the current line and place the cursor at the new line. After this change, `xc` will now clear a line but keep an empty line, where the cursor will start at. Test Plan: See new tests inside edit-insert --- extensions/helix/package.json | 45 +++++--------- package.json | 65 ++++---------------- src/api/data/commands.yaml | 40 ++++++++++--- src/commands/README.md | 80 +++++++++---------------- src/commands/edit.ts | 26 ++++++-- src/commands/layouts/azerty.fr.md | 80 +++++++++---------------- src/commands/layouts/qwerty.md | 80 +++++++++---------------- src/commands/load-all.ts | 16 ++++- test/suite/commands/edit-insert.md | 32 ++++++++++ test/suite/commands/edit-insert.test.ts | 38 ++++++++++++ 10 files changed, 245 insertions(+), 257 deletions(-) diff --git a/extensions/helix/package.json b/extensions/helix/package.json index fa59972a..09cfcbd6 100644 --- a/extensions/helix/package.json +++ b/extensions/helix/package.json @@ -1497,18 +1497,6 @@ "title": "Deindent selected lines (including incomplete indent)", "command": "dance.edit.deindent.withIncomplete" }, - { - "key": "Alt+D", - "when": "editorTextFocus && dance.mode == 'helix/normal'", - "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'", @@ -1587,24 +1575,6 @@ "title": "Replace characters", "command": "dance.edit.replaceCharacters" }, - { - "key": "D", - "when": "editorTextFocus && dance.mode == 'helix/normal'", - "title": "Copy and delete", - "command": "dance.edit.yank-delete" - }, - { - "key": "C", - "when": "editorTextFocus && dance.mode == 'helix/normal'", - "title": "Copy, delete and switch to Insert", - "command": "dance.edit.yank-delete-insert" - }, - { - "key": "C", - "when": "editorTextFocus && dance.mode == 'helix/select'", - "title": "Copy, delete and switch to Insert", - "command": "dance.edit.yank-delete-insert" - }, { "key": "Shift+.", "when": "editorTextFocus && dance.mode == 'helix/select'", @@ -3151,6 +3121,16 @@ "$exclude": [] } }, + { + "key": "C", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/normal'" + }, + { + "key": "D", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/normal'" + }, { "key": "Q", "command": "dance.ignore", @@ -3271,6 +3251,11 @@ "command": "dance.ignore", "when": "editorTextFocus && dance.mode == 'helix/normal'" }, + { + "key": "C", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'helix/select'" + }, { "key": "D", "command": "dance.ignore", diff --git a/package.json b/package.json index 8f76e28d..b9c36c70 100644 --- a/package.json +++ b/package.json @@ -1015,21 +1015,6 @@ "title": "Deindent selected lines (including incomplete indent)", "category": "Dance" }, - { - "command": "dance.edit.delete", - "title": "Delete", - "category": "Dance" - }, - { - "command": "dance.edit.delete-insert", - "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", @@ -1125,16 +1110,6 @@ "title": "Pick register and replace", "category": "Dance" }, - { - "command": "dance.edit.yank-delete", - "title": "Copy and delete", - "category": "Dance" - }, - { - "command": "dance.edit.yank-delete-insert", - "title": "Copy, delete and switch to Insert", - "category": "Dance" - }, { "command": "dance.edit.yank-replace", "title": "Copy and replace", @@ -2039,24 +2014,6 @@ "title": "Deindent selected lines (including incomplete indent)", "command": "dance.edit.deindent.withIncomplete" }, - { - "key": "Alt+D", - "when": "editorTextFocus && dance.mode == 'normal'", - "title": "Delete", - "command": "dance.edit.delete" - }, - { - "key": "Alt+C", - "when": "editorTextFocus && dance.mode == 'normal'", - "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'", @@ -2153,18 +2110,6 @@ "title": "Pick register and replace", "command": "dance.edit.selectRegister-insert" }, - { - "key": "D", - "when": "editorTextFocus && dance.mode == 'normal'", - "title": "Copy and delete", - "command": "dance.edit.yank-delete" - }, - { - "key": "C", - "when": "editorTextFocus && dance.mode == 'normal'", - "title": "Copy, delete and switch to Insert", - "command": "dance.edit.yank-delete-insert" - }, { "key": "Shift+R", "when": "editorTextFocus && dance.mode == 'normal'", @@ -3253,6 +3198,16 @@ "$exclude": [] } }, + { + "key": "C", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'normal'" + }, + { + "key": "D", + "command": "dance.ignore", + "when": "editorTextFocus && dance.mode == 'normal'" + }, { "key": "Shift+D", "command": "dance.ignore", diff --git a/src/api/data/commands.yaml b/src/api/data/commands.yaml index 4defc02e..519e0611 100644 --- a/src/api/data/commands.yaml +++ b/src/api/data/commands.yaml @@ -155,7 +155,7 @@ edit.delete: en: Delete commands: |- - [".edit.deleteSelections"] + [".edit.deleteSelections", { register: "_", $exclude: [] }] keys: qwerty: |- @@ -172,6 +172,17 @@ edit.delete-insert: qwerty: |- `a-c` (kakoune: normal) +edit.delete-insert-preserving-lines: + title: + en: Delete and switch to Insert preserving lines + + commands: |- + [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections", { preserveEntireLines: true, $exclude: ["mode"] }] + + keys: + qwerty: |- + `a-c` (helix: normal) + edit.deleteSelections: title: en: Delete contents of selection @@ -187,12 +198,14 @@ edit.deleteSelections: #### 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"]` | + | Title | Identifier | Keybinding | Commands | + | -------------------------------------------------- | ------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | + | Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections", { register: "_", ... }]` | + | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + | Delete and switch to Insert preserving lines | `delete-insert-preserving-lines` | `a-c` (helix: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections", { preserveEntireLines: true, ... }]` | + | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | + | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (kakoune: normal | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + | Copy, delete and switch to Insert preserving lines | `yank-delete-insert-preserving-lines` | `c` (helix: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections", { preserveEntireLines: true, ... }]` | edit.indent: title: @@ -472,7 +485,18 @@ edit.yank-delete-insert: keys: qwerty: |- - `c` (core: normal; helix: select) + `c` (kakoune: normal + +edit.yank-delete-insert-preserving-lines: + title: + en: Copy, delete and switch to Insert preserving lines + + commands: |- + [".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections", { preserveEntireLines: true, $exclude: ["register","mode"] }] + + keys: + qwerty: |- + `c` (helix: normal; helix: select) edit.yank-replace: title: diff --git a/src/commands/README.md b/src/commands/README.md index 9d77efe0..0aa35fdb 100644 --- a/src/commands/README.md +++ b/src/commands/README.md @@ -26,30 +26,25 @@ 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.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 -edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') -edit.pasteAll.afterPaste all after -edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') -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.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 +edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') +edit.pasteAll.afterPaste all after +edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') +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-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') @@ -266,7 +261,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](./edit.ts#L15-L57) +### [`edit.insert`](./edit.ts#L16-L58) Insert contents of register. @@ -308,28 +303,9 @@ This command: 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#L150-L155) +### [`edit.join`](./edit.ts#L180-L185) Join lines. @@ -342,7 +318,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](./edit.ts#L159-L164) +### [`edit.join.select`](./edit.ts#L189-L194) Join lines and select inserted separators. @@ -354,7 +330,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](./edit.ts#L168-L176) +### [`edit.indent`](./edit.ts#L198-L206) Indent selected lines. @@ -369,7 +345,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](./edit.ts#L180-L185) +### [`edit.indent.withEmpty`](./edit.ts#L210-L215) Indent selected lines (including empty lines). @@ -381,7 +357,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](./edit.ts#L189-L194) +### [`edit.deindent`](./edit.ts#L219-L224) Deindent selected lines. @@ -393,7 +369,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](./edit.ts#L198-L206) +### [`edit.deindent.withIncomplete`](./edit.ts#L228-L236) Deindent selected lines (including incomplete indent). @@ -408,7 +384,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](./edit.ts#L210-L218) +### [`edit.case.toLower`](./edit.ts#L240-L248) Transform to lower case. @@ -421,7 +397,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](./edit.ts#L222-L230) +### [`edit.case.toUpper`](./edit.ts#L252-L260) Transform to upper case. @@ -435,7 +411,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](./edit.ts#L234-L242) +### [`edit.case.swap`](./edit.ts#L264-L272) Swap case. @@ -449,7 +425,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](./edit.ts#L257-L269) +### [`edit.replaceCharacters`](./edit.ts#L287-L299) Replace characters. @@ -465,7 +441,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](./edit.ts#L312-L320) +### [`edit.align`](./edit.ts#L342-L350) Align selections. @@ -480,7 +456,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](./edit.ts#L370-L383) +### [`edit.copyIndentation`](./edit.ts#L400-L413) Copy indentation. @@ -495,7 +471,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](./edit.ts#L412-L430) +### [`edit.newLine.above`](./edit.ts#L442-L460) Insert new line above each selection. @@ -517,7 +493,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](./edit.ts#L450-L468) +### [`edit.newLine.below`](./edit.ts#L480-L498) Insert new line below each selection. diff --git a/src/commands/edit.ts b/src/commands/edit.ts index 470689cc..902965ab 100644 --- a/src/commands/edit.ts +++ b/src/commands/edit.ts @@ -4,6 +4,7 @@ import type { Argument, InputOr, RegisterOr } from "."; import { insert as apiInsert, Context, deindentLines, Direction, edit, indentLines, insertByIndex, insertByIndexWithFullLines, insertFlagsAtEdge, joinLines, keypress, Positions, replace, replaceByIndex, Selections, Shift } from "../api"; import type { Register } from "../state/registers"; import { ArgumentError, LengthMismatchError } from "../utils/errors"; +import { horizontally } from "./select"; /** * Perform changes on the text content of the document. @@ -133,18 +134,31 @@ export async function insert( * * #### 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"]` | + * | Title | Identifier | Keybinding | Commands | + * | -------------------------------------------------- | ------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | + * | Delete | `delete` | `a-d` (core: normal) | `[".edit.deleteSelections", { register: "_", ... }]` | + * | Delete and switch to Insert | `delete-insert` | `a-c` (kakoune: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + * | Delete and switch to Insert preserving lines | `delete-insert-preserving-lines` | `a-c` (helix: normal) | `[".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections", { preserveEntireLines: true, ... }]` | + * | Copy and delete | `yank-delete` | `d` (core: normal) | `[".selections.saveText", { +register }], [".edit.deleteSelections"]` | + * | Copy, delete and switch to Insert | `yank-delete-insert` | `c` (kakoune: normal | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections"]` | + * | Copy, delete and switch to Insert preserving lines | `yank-delete-insert-preserving-lines` | `c` (helix: normal; helix: select) | `[".selections.saveText", { +register }], [".modes.set", { mode: "insert", +mode }], [".edit.deleteSelections", { preserveEntireLines: true, ... }]` | */ export async function deleteSelections( _: Context, selections: readonly vscode.Selection[], + preserveEntireLines: Argument = false, ) { Selections.set(await replace((_) => "", selections)); + + if (preserveEntireLines) { + const onlyEntireLines = selections.every((selection, _i) => + Selections.isEntireLines(selection), + ); + if (onlyEntireLines) { + newLine_above(_, 1); + horizontally(_, false, 0, Direction.Backward, Shift.Jump); + } + } } /** diff --git a/src/commands/layouts/azerty.fr.md b/src/commands/layouts/azerty.fr.md index e664d6c1..fa5dfbd9 100644 --- a/src/commands/layouts/azerty.fr.md +++ b/src/commands/layouts/azerty.fr.md @@ -11,30 +11,25 @@ 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.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 -edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') -edit.pasteAll.afterPaste all after -edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') -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.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 +edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') +edit.pasteAll.afterPaste all after +edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') +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-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') @@ -251,7 +246,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](../edit.ts#L15-L57) +### [`edit.insert`](../edit.ts#L16-L58) Insert contents of register. @@ -293,28 +288,9 @@ This command: 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#L150-L155) +### [`edit.join`](../edit.ts#L180-L185) Join lines. @@ -327,7 +303,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](../edit.ts#L159-L164) +### [`edit.join.select`](../edit.ts#L189-L194) Join lines and select inserted separators. @@ -339,7 +315,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](../edit.ts#L168-L176) +### [`edit.indent`](../edit.ts#L198-L206) Indent selected lines. @@ -354,7 +330,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](../edit.ts#L180-L185) +### [`edit.indent.withEmpty`](../edit.ts#L210-L215) Indent selected lines (including empty lines). @@ -366,7 +342,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](../edit.ts#L189-L194) +### [`edit.deindent`](../edit.ts#L219-L224) Deindent selected lines. @@ -378,7 +354,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](../edit.ts#L198-L206) +### [`edit.deindent.withIncomplete`](../edit.ts#L228-L236) Deindent selected lines (including incomplete indent). @@ -393,7 +369,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](../edit.ts#L210-L218) +### [`edit.case.toLower`](../edit.ts#L240-L248) Transform to lower case. @@ -406,7 +382,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](../edit.ts#L222-L230) +### [`edit.case.toUpper`](../edit.ts#L252-L260) Transform to upper case. @@ -420,7 +396,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](../edit.ts#L234-L242) +### [`edit.case.swap`](../edit.ts#L264-L272) Swap case. @@ -434,7 +410,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](../edit.ts#L257-L269) +### [`edit.replaceCharacters`](../edit.ts#L287-L299) Replace characters. @@ -450,7 +426,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](../edit.ts#L312-L320) +### [`edit.align`](../edit.ts#L342-L350) Align selections. @@ -465,7 +441,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](../edit.ts#L370-L383) +### [`edit.copyIndentation`](../edit.ts#L400-L413) Copy indentation. @@ -480,7 +456,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](../edit.ts#L412-L430) +### [`edit.newLine.above`](../edit.ts#L442-L460) Insert new line above each selection. @@ -502,7 +478,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](../edit.ts#L450-L468) +### [`edit.newLine.below`](../edit.ts#L480-L498) Insert new line below each selection. diff --git a/src/commands/layouts/qwerty.md b/src/commands/layouts/qwerty.md index 2a0dbae0..fca1b30d 100644 --- a/src/commands/layouts/qwerty.md +++ b/src/commands/layouts/qwerty.md @@ -11,30 +11,25 @@ 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.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 -edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') -edit.pasteAll.afterPaste all after -edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') -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.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 +edit.paste.before.selectPaste before and selectShift+P (editorTextFocus && dance.mode == 'normal') +edit.pasteAll.afterPaste all after +edit.pasteAll.after.selectPaste all after and selectAlt+P (editorTextFocus && dance.mode == 'normal') +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-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') @@ -251,7 +246,7 @@ See https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes -### [`edit.insert`](../edit.ts#L15-L57) +### [`edit.insert`](../edit.ts#L16-L58) Insert contents of register. @@ -293,28 +288,9 @@ This command: 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#L150-L155) +### [`edit.join`](../edit.ts#L180-L185) Join lines. @@ -327,7 +303,7 @@ Default keybinding: `a-j` (kakoune: normal) -### [`edit.join.select`](../edit.ts#L159-L164) +### [`edit.join.select`](../edit.ts#L189-L194) Join lines and select inserted separators. @@ -339,7 +315,7 @@ Default keybinding: `s-a-j` (core: normal; helix: select) -### [`edit.indent`](../edit.ts#L168-L176) +### [`edit.indent`](../edit.ts#L198-L206) Indent selected lines. @@ -354,7 +330,7 @@ Default keybinding: `>` (core: normal) -### [`edit.indent.withEmpty`](../edit.ts#L180-L185) +### [`edit.indent.withEmpty`](../edit.ts#L210-L215) Indent selected lines (including empty lines). @@ -366,7 +342,7 @@ Default keybinding: `a->` (kakoune: normal) -### [`edit.deindent`](../edit.ts#L189-L194) +### [`edit.deindent`](../edit.ts#L219-L224) Deindent selected lines. @@ -378,7 +354,7 @@ Default keybinding: `a-<` (kakoune: normal) -### [`edit.deindent.withIncomplete`](../edit.ts#L198-L206) +### [`edit.deindent.withIncomplete`](../edit.ts#L228-L236) Deindent selected lines (including incomplete indent). @@ -393,7 +369,7 @@ Default keybinding: `<` (core: normal) -### [`edit.case.toLower`](../edit.ts#L210-L218) +### [`edit.case.toLower`](../edit.ts#L240-L248) Transform to lower case. @@ -406,7 +382,7 @@ Default keybinding: `` ` `` (core: normal) -### [`edit.case.toUpper`](../edit.ts#L222-L230) +### [`edit.case.toUpper`](../edit.ts#L252-L260) Transform to upper case. @@ -420,7 +396,7 @@ Default keybinding: `` s-` `` (kakoune: normal) -### [`edit.case.swap`](../edit.ts#L234-L242) +### [`edit.case.swap`](../edit.ts#L264-L272) Swap case. @@ -434,7 +410,7 @@ Default keybinding: `` a-` `` (kakoune: normal) -### [`edit.replaceCharacters`](../edit.ts#L257-L269) +### [`edit.replaceCharacters`](../edit.ts#L287-L299) Replace characters. @@ -450,7 +426,7 @@ Default keybinding: `r` (core: normal) -### [`edit.align`](../edit.ts#L312-L320) +### [`edit.align`](../edit.ts#L342-L350) Align selections. @@ -465,7 +441,7 @@ Default keybinding: `&` (core: normal) -### [`edit.copyIndentation`](../edit.ts#L370-L383) +### [`edit.copyIndentation`](../edit.ts#L400-L413) Copy indentation. @@ -480,7 +456,7 @@ Default keybinding: `a-&` (kakoune: normal) -### [`edit.newLine.above`](../edit.ts#L412-L430) +### [`edit.newLine.above`](../edit.ts#L442-L460) Insert new line above each selection. @@ -502,7 +478,7 @@ Default keybinding: `s-a-o` (kakoune: normal) -### [`edit.newLine.below`](../edit.ts#L450-L468) +### [`edit.newLine.below`](../edit.ts#L480-L498) Insert new line below each selection. diff --git a/src/commands/load-all.ts b/src/commands/load-all.ts index 30c60e18..1555b29a 100644 --- a/src/commands/load-all.ts +++ b/src/commands/load-all.ts @@ -337,7 +337,7 @@ export const commands: Commands = function () { ), "dance.edit.deleteSelections": new CommandDescriptor( "dance.edit.deleteSelections", - (_) => _.runAsync(async (_) => await edit_deleteSelections(_, _.selections)), + (_, argument) => _.runAsync(async (_) => await edit_deleteSelections(_, _.selections, argument["preserveEntireLines"])), CommandDescriptor.Flags.RequiresActiveEditor, ), "dance.edit.indent": new CommandDescriptor( @@ -792,7 +792,7 @@ export const commands: Commands = function () { commands, "dance.edit.delete", CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".edit.deleteSelections"]], + [[".edit.deleteSelections", { register: "_", $exclude: [] }]], ); describeAdditionalCommand( commands, @@ -800,6 +800,12 @@ export const commands: Commands = function () { CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, [[".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"]], ); + describeAdditionalCommand( + commands, + "dance.edit.delete-insert-preserving-lines", + CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, + [[".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections", { preserveEntireLines: true, $exclude: ["mode"] }]], + ); describeAdditionalCommand( commands, "dance.edit.yank-delete", @@ -812,6 +818,12 @@ export const commands: Commands = function () { CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, [[".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections"]], ); + describeAdditionalCommand( + commands, + "dance.edit.yank-delete-insert-preserving-lines", + CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, + [[".selections.saveText", { $include: ["register"] }], [".modes.set", { mode: "insert", $include: ["mode"] }], [".edit.deleteSelections", { preserveEntireLines: true, $exclude: ["register","mode"] }]], + ); describeAdditionalCommand( commands, "dance.history.repeat.selection", diff --git a/test/suite/commands/edit-insert.md b/test/suite/commands/edit-insert.md index 1dcbfe35..943bfd2b 100644 --- a/test/suite/commands/edit-insert.md +++ b/test/suite/commands/edit-insert.md @@ -36,3 +36,35 @@ fooar foor ^ 0 ``` + +# 2 + +``` +foo + ^ 0 +bar +``` + +## 2 delete-line +[up](#2) + +- .select.line.below.extend +- .edit.delete + +``` +bar +| 0 +``` + +## 2 delete-line-preserving-lines +[up](#2) + +- .select.line.below.extend +- .edit.delete-insert-preserving-lines + +``` + +| 0 +bar +``` + diff --git a/test/suite/commands/edit-insert.test.ts b/test/suite/commands/edit-insert.test.ts index 9e995b7d..e760187d 100644 --- a/test/suite/commands/edit-insert.test.ts +++ b/test/suite/commands/edit-insert.test.ts @@ -75,5 +75,43 @@ suite("./test/suite/commands/edit-insert.md", function () { `); }); + test("2 > delete-line", async function () { + // Set-up document to be in expected initial state. + await ExpectedDocument.apply(editor, 6, String.raw` + foo + ^ 0 + bar + `); + + // Perform all operations. + await executeCommand("dance.select.line.below.extend"); + await executeCommand("dance.edit.delete"); + + // Ensure document is as expected. + ExpectedDocument.assertEquals(editor, "./test/suite/commands/edit-insert.md:48:1", 6, String.raw` + bar + | 0 + `); + }); + + test("2 > delete-line-preserving-lines", async function () { + // Set-up document to be in expected initial state. + await ExpectedDocument.apply(editor, 6, String.raw` + foo + ^ 0 + bar + `); + + // Perform all operations. + await executeCommand("dance.select.line.below.extend"); + + // Ensure document is as expected. + ExpectedDocument.assertEquals(editor, "./test/suite/commands/edit-insert.md:59:1", 6, String.raw` + + | 0 + bar + `); + }); + groupTestsByParentName(this); });