From 81cee59f1753e10f380903c02482da586181a55b Mon Sep 17 00:00:00 2001 From: Sebastian Doerner Date: Mon, 13 Oct 2025 12:13:33 +0200 Subject: [PATCH] Add an explicit dance.selections.clear command. This allows using this functionality within environments that prohibit arbitrary code execution (such as certain CSPs). This essentially forks filter() and removes interactive expression selection. Fixes: #349 --- extensions/helix/package.json | 8 ++-- package.json | 8 ++-- src/api/data/commands.yaml | 16 +++---- src/commands/README.md | 74 +++++++++++++++++++------------ src/commands/layouts/azerty.fr.md | 74 +++++++++++++++++++------------ src/commands/layouts/qwerty.md | 74 +++++++++++++++++++------------ src/commands/load-all.ts | 24 +++++----- src/commands/selections.ts | 22 ++++++++- 8 files changed, 183 insertions(+), 117 deletions(-) diff --git a/extensions/helix/package.json b/extensions/helix/package.json index 0d31642..0777b91 100644 --- a/extensions/helix/package.json +++ b/extensions/helix/package.json @@ -2899,25 +2899,25 @@ { "key": "Alt+,", "when": "editorTextFocus && dance.mode == 'helix/normal'", - "title": "Clear main selections", + "title": "Clear main selection", "command": "dance.selections.clear.main" }, { "key": "Alt+,", "when": "editorTextFocus && dance.mode == 'helix/select'", - "title": "Clear main selections", + "title": "Clear main selection", "command": "dance.selections.clear.main" }, { "key": ",", "when": "editorTextFocus && dance.mode == 'helix/normal'", - "title": "Clear secondary selections", + "title": "Clear all secondary selections", "command": "dance.selections.clear.secondary" }, { "key": ",", "when": "editorTextFocus && dance.mode == 'helix/select'", - "title": "Clear secondary selections", + "title": "Clear all secondary selections", "command": "dance.selections.clear.secondary" }, { diff --git a/package.json b/package.json index b228a0c..42a7732 100644 --- a/package.json +++ b/package.json @@ -1782,12 +1782,12 @@ }, { "command": "dance.selections.clear.main", - "title": "Clear main selections", + "title": "Clear main selection", "category": "Dance" }, { "command": "dance.selections.clear.secondary", - "title": "Clear secondary selections", + "title": "Clear all secondary selections", "category": "Dance" }, { @@ -3035,13 +3035,13 @@ { "key": "Alt+,", "when": "editorTextFocus && dance.mode == 'normal'", - "title": "Clear main selections", + "title": "Clear main selection", "command": "dance.selections.clear.main" }, { "key": ",", "when": "editorTextFocus && dance.mode == 'normal'", - "title": "Clear secondary selections", + "title": "Clear all secondary selections", "command": "dance.selections.clear.secondary" }, { diff --git a/src/api/data/commands.yaml b/src/api/data/commands.yaml index 06ddf79..78398f6 100644 --- a/src/api/data/commands.yaml +++ b/src/api/data/commands.yaml @@ -2114,10 +2114,11 @@ selections.changeOrder: selections.clear.main: title: - en: Clear main selections + en: Clear main selection - commands: |- - [".selections.filter", { expression: "i !== count" , $exclude: [] }] + doc: + en: | + Clear main selection. keys: qwerty: |- @@ -2125,10 +2126,11 @@ selections.clear.main: selections.clear.secondary: title: - en: Clear secondary selections + en: Clear all secondary selections - commands: |- - [".selections.filter", { expression: "i === count" , $exclude: [] }] + doc: + en: | + Clear all secondary selections. keys: qwerty: |- @@ -2215,8 +2217,6 @@ selections.filter: | -------------------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------ | | Keep matching selections | `filter.regexp` | `a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/" , ... }]` | | Clear matching selections | `filter.regexp.inverse` | `s-a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/", inverse: true, ... }]` | - | Clear secondary selections | `clear.secondary` | `,` (core: normal; helix: select) | `[".selections.filter", { expression: "i === count" , ... }]` | - | Clear main selections | `clear.main` | `a-,` (core: normal; helix: select) | `[".selections.filter", { expression: "i !== count" , ... }]` | selections.filter.regexp: title: diff --git a/src/commands/README.md b/src/commands/README.md index d05617c..05e38c4 100644 --- a/src/commands/README.md +++ b/src/commands/README.md @@ -187,6 +187,8 @@ selections are empty select.verticallySelect vertically selectionsselections.changeDirectionChange direction of selectionsAlt+; (editorTextFocus && dance.mode == 'normal')Alt+; (editorTextFocus && dance.mode == 'select') selections.changeOrderReverse selections +selections.clear.mainClear main selectionAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') +selections.clear.secondaryClear all secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') selections.copyCopy selections belowShift+C (editorTextFocus && dance.mode == 'normal')Shift+C (editorTextFocus && dance.mode == 'select') selections.expandToLinesExpand to linesX (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'select') selections.filterFilter selectionsShift+4 (editorTextFocus && dance.mode == 'normal')Shift+4 (editorTextFocus && dance.mode == 'select') @@ -199,23 +201,21 @@ selections are empty selections.saveSave selectionsShift+Z (editorTextFocus && dance.mode == 'normal') selections.saveTextCopy selections textY (editorTextFocus && dance.mode == 'normal') selections.selectSelect within selections -selections.clear.mainClear main selectionsAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') -selections.clear.secondaryClear secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') -selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') -selections.faceBackwardBackward selections -selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') +selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') +selections.faceBackwardBackward selections +selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') selections.filter.regexpKeep matching selectionsAlt+K (editorTextFocus && dance.mode == 'normal')Alt+K (editorTextFocus && dance.mode == 'select') selections.filter.regexp.inverseClear matching selectionsShift+Alt+K (editorTextFocus && dance.mode == 'normal')Shift+Alt+K (editorTextFocus && dance.mode == 'select') -selections.hideIndicesHide selection indices -selections.orderAscendingOrder selections ascending -selections.orderDescendingOrder selections descending +selections.hideIndicesHide selection indices +selections.orderAscendingOrder selections ascending +selections.orderDescendingOrder selections descending selections.pipe.appendPipe and appendShift+1 (editorTextFocus && dance.mode == 'normal')Shift+1 (editorTextFocus && dance.mode == 'select') selections.pipe.prependPipe and prependShift+Alt+1 (editorTextFocus && dance.mode == 'normal')Shift+Alt+1 (editorTextFocus && dance.mode == 'select') selections.pipe.replacePipe and replaceShift+\ (editorTextFocus && dance.mode == 'normal')Shift+\ (editorTextFocus && dance.mode == 'select') -selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') -selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') -selections.showIndicesShow selection indices -selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') +selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') +selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') +selections.showIndicesShow selection indices +selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') selections.sortSort selections selections.splitSplit selectionsShift+S (editorTextFocus && dance.mode == 'normal')Shift+S (editorTextFocus && dance.mode == 'select') selections.splitLinesSplit selections at line boundaries @@ -1541,7 +1541,7 @@ Default keybinding: `a-|` (core: normal; helix: select) -### [`selections.filter`](./selections.ts#L293-L314) +### [`selections.filter`](./selections.ts#L293-L312) Filter selections. @@ -1551,8 +1551,6 @@ Filter selections. | -------------------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------ | | Keep matching selections | `filter.regexp` | `a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/" , ... }]` | | Clear matching selections | `filter.regexp.inverse` | `s-a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/", inverse: true, ... }]` | -| Clear secondary selections | `clear.secondary` | `,` (core: normal; helix: select) | `[".selections.filter", { expression: "i === count" , ... }]` | -| Clear main selections | `clear.main` | `a-,` (core: normal; helix: select) | `[".selections.filter", { expression: "i !== count" , ... }]` | This command: - accepts an argument of type `{ expression?: string }`. @@ -1563,9 +1561,27 @@ This command: Default keybinding: `$` (core: normal; helix: select) + + +### [`selections.clear.secondary`](./selections.ts#L345-L351) + +Clear all secondary selections. + + +Default keybinding: `,` (core: normal; helix: select) + + + +### [`selections.clear.main`](./selections.ts#L355-L361) + +Clear main selection. + + +Default keybinding: `a-,` (core: normal; helix: select) + -### [`selections.select`](./selections.ts#L347-L362) +### [`selections.select`](./selections.ts#L365-L380) Select within selections. @@ -1582,7 +1598,7 @@ This command: -### [`selections.split`](./selections.ts#L383-L395) +### [`selections.split`](./selections.ts#L401-L413) Split selections. @@ -1597,7 +1613,7 @@ Default keybinding: `s-s` (core: normal; helix: select) -### [`selections.splitLines`](./selections.ts#L422-L438) +### [`selections.splitLines`](./selections.ts#L440-L456) Split selections at line boundaries. @@ -1613,7 +1629,7 @@ This command: -### [`selections.expandToLines`](./selections.ts#L481-L488) +### [`selections.expandToLines`](./selections.ts#L499-L506) Expand to lines. @@ -1626,7 +1642,7 @@ Default keybinding: `x` (kakoune: normal) -### [`selections.trimLines`](./selections.ts#L515-L522) +### [`selections.trimLines`](./selections.ts#L533-L540) Trim lines. @@ -1638,7 +1654,7 @@ Default keybinding: `a-x` (core: normal; helix: select) -### [`selections.trimWhitespace`](./selections.ts#L547-L554) +### [`selections.trimWhitespace`](./selections.ts#L565-L572) Trim whitespace. @@ -1650,7 +1666,7 @@ Default keybinding: `_` (core: normal; helix: select) -### [`selections.reduce`](./selections.ts#L573-L592) +### [`selections.reduce`](./selections.ts#L591-L610) Reduce selections to their cursor. @@ -1670,7 +1686,7 @@ Default keybinding: `;` (core: normal; helix: select) -### [`selections.changeDirection`](./selections.ts#L654-L669) +### [`selections.changeDirection`](./selections.ts#L672-L687) Change direction of selections. @@ -1688,7 +1704,7 @@ Default keybinding: `a-;` (core: normal; helix: select) -### [`selections.changeOrder`](./selections.ts#L694-L708) +### [`selections.changeOrder`](./selections.ts#L712-L726) Reverse selections. @@ -1702,7 +1718,7 @@ Reverse selections. -### [`selections.sort`](./selections.ts#L721-L733) +### [`selections.sort`](./selections.ts#L739-L751) Sort selections. @@ -1713,7 +1729,7 @@ This command: -### [`selections.copy`](./selections.ts#L806-L824) +### [`selections.copy`](./selections.ts#L824-L842) Copy selections below. @@ -1731,7 +1747,7 @@ Default keybinding: `s-c` (core: normal; helix: select) -### [`selections.merge`](./selections.ts#L858-L863) +### [`selections.merge`](./selections.ts#L876-L881) Merge contiguous selections. @@ -1741,13 +1757,13 @@ Default keybinding: `a-_` (kakoune: normal) -### [`selections.open`](./selections.ts#L867-L870) +### [`selections.open`](./selections.ts#L885-L888) Open selected file. -### [`selections.toggleIndices`](./selections.ts#L883-L900) +### [`selections.toggleIndices`](./selections.ts#L901-L918) Toggle selection indices. diff --git a/src/commands/layouts/azerty.fr.md b/src/commands/layouts/azerty.fr.md index a946f9d..c9ad209 100644 --- a/src/commands/layouts/azerty.fr.md +++ b/src/commands/layouts/azerty.fr.md @@ -172,6 +172,8 @@ selections are empty select.verticallySelect vertically selectionsselections.changeDirectionChange direction of selectionsAlt+; (editorTextFocus && dance.mode == 'normal')Alt+; (editorTextFocus && dance.mode == 'select') selections.changeOrderReverse selections +selections.clear.mainClear main selectionAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') +selections.clear.secondaryClear all secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') selections.copyCopy selections belowShift+C (editorTextFocus && dance.mode == 'normal')Shift+C (editorTextFocus && dance.mode == 'select') selections.expandToLinesExpand to linesX (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'select') selections.filterFilter selectionsShift+4 (editorTextFocus && dance.mode == 'normal')Shift+4 (editorTextFocus && dance.mode == 'select') @@ -184,23 +186,21 @@ selections are empty selections.saveSave selectionsShift+Z (editorTextFocus && dance.mode == 'normal') selections.saveTextCopy selections textY (editorTextFocus && dance.mode == 'normal') selections.selectSelect within selections -selections.clear.mainClear main selectionsAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') -selections.clear.secondaryClear secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') -selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') -selections.faceBackwardBackward selections -selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') +selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') +selections.faceBackwardBackward selections +selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') selections.filter.regexpKeep matching selectionsAlt+K (editorTextFocus && dance.mode == 'normal')Alt+K (editorTextFocus && dance.mode == 'select') selections.filter.regexp.inverseClear matching selectionsShift+Alt+K (editorTextFocus && dance.mode == 'normal')Shift+Alt+K (editorTextFocus && dance.mode == 'select') -selections.hideIndicesHide selection indices -selections.orderAscendingOrder selections ascending -selections.orderDescendingOrder selections descending +selections.hideIndicesHide selection indices +selections.orderAscendingOrder selections ascending +selections.orderDescendingOrder selections descending selections.pipe.appendPipe and appendShift+1 (editorTextFocus && dance.mode == 'normal')Shift+1 (editorTextFocus && dance.mode == 'select') selections.pipe.prependPipe and prependShift+Alt+1 (editorTextFocus && dance.mode == 'normal')Shift+Alt+1 (editorTextFocus && dance.mode == 'select') selections.pipe.replacePipe and replaceShift+\ (editorTextFocus && dance.mode == 'normal')Shift+\ (editorTextFocus && dance.mode == 'select') -selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') -selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') -selections.showIndicesShow selection indices -selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') +selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') +selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') +selections.showIndicesShow selection indices +selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') selections.sortSort selections selections.splitSplit selectionsShift+S (editorTextFocus && dance.mode == 'normal')Shift+S (editorTextFocus && dance.mode == 'select') selections.splitLinesSplit selections at line boundaries @@ -1526,7 +1526,7 @@ Default keybinding: `a-|` (core: normal; helix: select) -### [`selections.filter`](../selections.ts#L293-L314) +### [`selections.filter`](../selections.ts#L293-L312) Filter selections. @@ -1536,8 +1536,6 @@ Filter selections. | -------------------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------ | | Keep matching selections | `filter.regexp` | `a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/" , ... }]` | | Clear matching selections | `filter.regexp.inverse` | `s-a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/", inverse: true, ... }]` | -| Clear secondary selections | `clear.secondary` | `,` (core: normal; helix: select) | `[".selections.filter", { expression: "i === count" , ... }]` | -| Clear main selections | `clear.main` | `a-,` (core: normal; helix: select) | `[".selections.filter", { expression: "i !== count" , ... }]` | This command: - accepts an argument of type `{ expression?: string }`. @@ -1548,9 +1546,27 @@ This command: Default keybinding: `$` (core: normal; helix: select) + + +### [`selections.clear.secondary`](../selections.ts#L345-L351) + +Clear all secondary selections. + + +Default keybinding: `,` (core: normal; helix: select) + + + +### [`selections.clear.main`](../selections.ts#L355-L361) + +Clear main selection. + + +Default keybinding: `a-,` (core: normal; helix: select) + -### [`selections.select`](../selections.ts#L347-L362) +### [`selections.select`](../selections.ts#L365-L380) Select within selections. @@ -1567,7 +1583,7 @@ This command: -### [`selections.split`](../selections.ts#L383-L395) +### [`selections.split`](../selections.ts#L401-L413) Split selections. @@ -1582,7 +1598,7 @@ Default keybinding: `s-s` (core: normal; helix: select) -### [`selections.splitLines`](../selections.ts#L422-L438) +### [`selections.splitLines`](../selections.ts#L440-L456) Split selections at line boundaries. @@ -1598,7 +1614,7 @@ This command: -### [`selections.expandToLines`](../selections.ts#L481-L488) +### [`selections.expandToLines`](../selections.ts#L499-L506) Expand to lines. @@ -1611,7 +1627,7 @@ Default keybinding: `x` (kakoune: normal) -### [`selections.trimLines`](../selections.ts#L515-L522) +### [`selections.trimLines`](../selections.ts#L533-L540) Trim lines. @@ -1623,7 +1639,7 @@ Default keybinding: `a-x` (core: normal; helix: select) -### [`selections.trimWhitespace`](../selections.ts#L547-L554) +### [`selections.trimWhitespace`](../selections.ts#L565-L572) Trim whitespace. @@ -1635,7 +1651,7 @@ Default keybinding: `_` (core: normal; helix: select) -### [`selections.reduce`](../selections.ts#L573-L592) +### [`selections.reduce`](../selections.ts#L591-L610) Reduce selections to their cursor. @@ -1655,7 +1671,7 @@ Default keybinding: `;` (core: normal; helix: select) -### [`selections.changeDirection`](../selections.ts#L654-L669) +### [`selections.changeDirection`](../selections.ts#L672-L687) Change direction of selections. @@ -1673,7 +1689,7 @@ Default keybinding: `a-;` (core: normal; helix: select) -### [`selections.changeOrder`](../selections.ts#L694-L708) +### [`selections.changeOrder`](../selections.ts#L712-L726) Reverse selections. @@ -1687,7 +1703,7 @@ Reverse selections. -### [`selections.sort`](../selections.ts#L721-L733) +### [`selections.sort`](../selections.ts#L739-L751) Sort selections. @@ -1698,7 +1714,7 @@ This command: -### [`selections.copy`](../selections.ts#L806-L824) +### [`selections.copy`](../selections.ts#L824-L842) Copy selections below. @@ -1716,7 +1732,7 @@ Default keybinding: `s-c` (core: normal; helix: select) -### [`selections.merge`](../selections.ts#L858-L863) +### [`selections.merge`](../selections.ts#L876-L881) Merge contiguous selections. @@ -1726,13 +1742,13 @@ Default keybinding: `a-_` (kakoune: normal) -### [`selections.open`](../selections.ts#L867-L870) +### [`selections.open`](../selections.ts#L885-L888) Open selected file. -### [`selections.toggleIndices`](../selections.ts#L883-L900) +### [`selections.toggleIndices`](../selections.ts#L901-L918) Toggle selection indices. diff --git a/src/commands/layouts/qwerty.md b/src/commands/layouts/qwerty.md index ca02433..f79f574 100644 --- a/src/commands/layouts/qwerty.md +++ b/src/commands/layouts/qwerty.md @@ -172,6 +172,8 @@ selections are empty select.verticallySelect vertically selectionsselections.changeDirectionChange direction of selectionsAlt+; (editorTextFocus && dance.mode == 'normal')Alt+; (editorTextFocus && dance.mode == 'select') selections.changeOrderReverse selections +selections.clear.mainClear main selectionAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') +selections.clear.secondaryClear all secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') selections.copyCopy selections belowShift+C (editorTextFocus && dance.mode == 'normal')Shift+C (editorTextFocus && dance.mode == 'select') selections.expandToLinesExpand to linesX (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'normal')Shift+X (editorTextFocus && dance.mode == 'select') selections.filterFilter selectionsShift+4 (editorTextFocus && dance.mode == 'normal')Shift+4 (editorTextFocus && dance.mode == 'select') @@ -184,23 +186,21 @@ selections are empty selections.saveSave selectionsShift+Z (editorTextFocus && dance.mode == 'normal') selections.saveTextCopy selections textY (editorTextFocus && dance.mode == 'normal') selections.selectSelect within selections -selections.clear.mainClear main selectionsAlt+, (editorTextFocus && dance.mode == 'normal')Alt+, (editorTextFocus && dance.mode == 'select') -selections.clear.secondaryClear secondary selections, (editorTextFocus && dance.mode == 'normal'), (editorTextFocus && dance.mode == 'select') -selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') -selections.faceBackwardBackward selections -selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') +selections.copy.aboveCopy selections aboveShift+Alt+C (editorTextFocus && dance.mode == 'normal')Shift+Alt+C (editorTextFocus && dance.mode == 'select') +selections.faceBackwardBackward selections +selections.faceForwardForward selectionsShift+Alt+; (editorTextFocus && dance.mode == 'normal') selections.filter.regexpKeep matching selectionsAlt+K (editorTextFocus && dance.mode == 'normal')Alt+K (editorTextFocus && dance.mode == 'select') selections.filter.regexp.inverseClear matching selectionsShift+Alt+K (editorTextFocus && dance.mode == 'normal')Shift+Alt+K (editorTextFocus && dance.mode == 'select') -selections.hideIndicesHide selection indices -selections.orderAscendingOrder selections ascending -selections.orderDescendingOrder selections descending +selections.hideIndicesHide selection indices +selections.orderAscendingOrder selections ascending +selections.orderDescendingOrder selections descending selections.pipe.appendPipe and appendShift+1 (editorTextFocus && dance.mode == 'normal')Shift+1 (editorTextFocus && dance.mode == 'select') selections.pipe.prependPipe and prependShift+Alt+1 (editorTextFocus && dance.mode == 'normal')Shift+Alt+1 (editorTextFocus && dance.mode == 'select') selections.pipe.replacePipe and replaceShift+\ (editorTextFocus && dance.mode == 'normal')Shift+\ (editorTextFocus && dance.mode == 'select') -selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') -selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') -selections.showIndicesShow selection indices -selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') +selections.reduce.edgesReduce selections to their endsShift+Alt+S (editorTextFocus && dance.mode == 'normal') +selections.select.orLeapLeap or selectS (editorTextFocus && dance.mode == 'normal')S (editorTextFocus && dance.mode == 'select') +selections.showIndicesShow selection indices +selections.splitLines.orLeap.backwardLeap or select backwardAlt+S (editorTextFocus && dance.mode == 'normal')Alt+S (editorTextFocus && dance.mode == 'select') selections.sortSort selections selections.splitSplit selectionsShift+S (editorTextFocus && dance.mode == 'normal')Shift+S (editorTextFocus && dance.mode == 'select') selections.splitLinesSplit selections at line boundaries @@ -1526,7 +1526,7 @@ Default keybinding: `a-|` (core: normal; helix: select) -### [`selections.filter`](../selections.ts#L293-L314) +### [`selections.filter`](../selections.ts#L293-L312) Filter selections. @@ -1536,8 +1536,6 @@ Filter selections. | -------------------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------ | | Keep matching selections | `filter.regexp` | `a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/" , ... }]` | | Clear matching selections | `filter.regexp.inverse` | `s-a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/", inverse: true, ... }]` | -| Clear secondary selections | `clear.secondary` | `,` (core: normal; helix: select) | `[".selections.filter", { expression: "i === count" , ... }]` | -| Clear main selections | `clear.main` | `a-,` (core: normal; helix: select) | `[".selections.filter", { expression: "i !== count" , ... }]` | This command: - accepts an argument of type `{ expression?: string }`. @@ -1548,9 +1546,27 @@ This command: Default keybinding: `$` (core: normal; helix: select) + + +### [`selections.clear.secondary`](../selections.ts#L345-L351) + +Clear all secondary selections. + + +Default keybinding: `,` (core: normal; helix: select) + + + +### [`selections.clear.main`](../selections.ts#L355-L361) + +Clear main selection. + + +Default keybinding: `a-,` (core: normal; helix: select) + -### [`selections.select`](../selections.ts#L347-L362) +### [`selections.select`](../selections.ts#L365-L380) Select within selections. @@ -1567,7 +1583,7 @@ This command: -### [`selections.split`](../selections.ts#L383-L395) +### [`selections.split`](../selections.ts#L401-L413) Split selections. @@ -1582,7 +1598,7 @@ Default keybinding: `s-s` (core: normal; helix: select) -### [`selections.splitLines`](../selections.ts#L422-L438) +### [`selections.splitLines`](../selections.ts#L440-L456) Split selections at line boundaries. @@ -1598,7 +1614,7 @@ This command: -### [`selections.expandToLines`](../selections.ts#L481-L488) +### [`selections.expandToLines`](../selections.ts#L499-L506) Expand to lines. @@ -1611,7 +1627,7 @@ Default keybinding: `x` (kakoune: normal) -### [`selections.trimLines`](../selections.ts#L515-L522) +### [`selections.trimLines`](../selections.ts#L533-L540) Trim lines. @@ -1623,7 +1639,7 @@ Default keybinding: `a-x` (core: normal; helix: select) -### [`selections.trimWhitespace`](../selections.ts#L547-L554) +### [`selections.trimWhitespace`](../selections.ts#L565-L572) Trim whitespace. @@ -1635,7 +1651,7 @@ Default keybinding: `_` (core: normal; helix: select) -### [`selections.reduce`](../selections.ts#L573-L592) +### [`selections.reduce`](../selections.ts#L591-L610) Reduce selections to their cursor. @@ -1655,7 +1671,7 @@ Default keybinding: `;` (core: normal; helix: select) -### [`selections.changeDirection`](../selections.ts#L654-L669) +### [`selections.changeDirection`](../selections.ts#L672-L687) Change direction of selections. @@ -1673,7 +1689,7 @@ Default keybinding: `a-;` (core: normal; helix: select) -### [`selections.changeOrder`](../selections.ts#L694-L708) +### [`selections.changeOrder`](../selections.ts#L712-L726) Reverse selections. @@ -1687,7 +1703,7 @@ Reverse selections. -### [`selections.sort`](../selections.ts#L721-L733) +### [`selections.sort`](../selections.ts#L739-L751) Sort selections. @@ -1698,7 +1714,7 @@ This command: -### [`selections.copy`](../selections.ts#L806-L824) +### [`selections.copy`](../selections.ts#L824-L842) Copy selections below. @@ -1716,7 +1732,7 @@ Default keybinding: `s-c` (core: normal; helix: select) -### [`selections.merge`](../selections.ts#L858-L863) +### [`selections.merge`](../selections.ts#L876-L881) Merge contiguous selections. @@ -1726,13 +1742,13 @@ Default keybinding: `a-_` (kakoune: normal) -### [`selections.open`](../selections.ts#L867-L870) +### [`selections.open`](../selections.ts#L885-L888) Open selected file. -### [`selections.toggleIndices`](../selections.ts#L883-L900) +### [`selections.toggleIndices`](../selections.ts#L901-L918) Toggle selection indices. diff --git a/src/commands/load-all.ts b/src/commands/load-all.ts index 196903c..11eec32 100644 --- a/src/commands/load-all.ts +++ b/src/commands/load-all.ts @@ -241,6 +241,8 @@ import { import { changeDirection as selections_changeDirection, changeOrder as selections_changeOrder, + clear_main as selections_clear_main, + clear_secondary as selections_clear_secondary, copy as selections_copy, expandToLines as selections_expandToLines, filter as selections_filter, @@ -587,6 +589,16 @@ export const commands: Commands = function () { (_, argument) => _.runAsync(async (_) => await selections_changeOrder(_, _.selections.slice(), getDirection(argument))), CommandDescriptor.Flags.RequiresActiveEditor, ), + "dance.selections.clear.main": new CommandDescriptor( + "dance.selections.clear.main", + (_) => _.runAsync(async (_) => await selections_clear_main(_)), + CommandDescriptor.Flags.RequiresActiveEditor, + ), + "dance.selections.clear.secondary": new CommandDescriptor( + "dance.selections.clear.secondary", + (_) => _.runAsync(async (_) => await selections_clear_secondary(_)), + CommandDescriptor.Flags.RequiresActiveEditor, + ), "dance.selections.copy": new CommandDescriptor( "dance.selections.copy", (_, argument) => _.runAsync(async (_) => await selections_copy(_, _.document, _.selections, getRepetitions(_, argument), getDirection(argument))), @@ -1304,18 +1316,6 @@ export const commands: Commands = function () { CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, [[".selections.filter", { defaultExpression: "/", inverse: true, $exclude: [] }]], ); - describeAdditionalCommand( - commands, - "dance.selections.clear.secondary", - CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".selections.filter", { expression: "i === count" , $exclude: [] }]], - ); - describeAdditionalCommand( - commands, - "dance.selections.clear.main", - CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay, - [[".selections.filter", { expression: "i !== count" , $exclude: [] }]], - ); describeAdditionalCommand( commands, "dance.selections.select.orLeap", diff --git a/src/commands/selections.ts b/src/commands/selections.ts index 9546f65..e38e846 100644 --- a/src/commands/selections.ts +++ b/src/commands/selections.ts @@ -300,8 +300,6 @@ const filterHistory: string[] = []; * | -------------------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------ | * | Keep matching selections | `filter.regexp` | `a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/" , ... }]` | * | Clear matching selections | `filter.regexp.inverse` | `s-a-k` (core: normal; helix: select) | `[".selections.filter", { defaultExpression: "/", inverse: true, ... }]` | - * | Clear secondary selections | `clear.secondary` | `,` (core: normal; helix: select) | `[".selections.filter", { expression: "i === count" , ... }]` | - * | Clear main selections | `clear.main` | `a-,` (core: normal; helix: select) | `[".selections.filter", { expression: "i !== count" , ... }]` | */ export function filter( _: Context, @@ -344,6 +342,26 @@ export function filter( }); } +/** + * Clear all secondary selections. + * @keys `,` (core: normal; helix: select) + */ +export function clear_secondary( + _: Context, +) { + Selections.set(_.selections.slice(0, 1)); +} + +/** + * Clear main selection. + * @keys `a-,` (core: normal; helix: select) + */ +export function clear_main( + _: Context, +) { + Selections.set(_.selections.slice(1)); +} + /** * Select within selections. *