From b8be0197dee44b7c3fd499315b15e90d75b28d78 Mon Sep 17 00:00:00 2001 From: jay23606 <4602056+jay23606@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:15:30 -0500 Subject: [PATCH 1/2] Add rewrap action to keyboard mode --- packages/app-vscode/package.json | 7 ++++--- .../src/keyboard/KeyboardActionType.ts | 12 +++++++----- .../src/keyboard/KeyboardCommandHandler.ts | 5 +++-- .../src/keyboard/KeyboardCommandsTargeted.ts | 1 - packages/app-vscode/src/keyboard/TokenTypes.ts | 2 +- .../getPairedDelimiterCommandName.test.ts | 18 ++++++++++++++++++ .../keyboard/getPairedDelimiterCommandName.ts | 17 +++++++++++++++++ .../src/keyboard/getTokenTypeKeyMaps.ts | 2 +- .../src/keyboard/grammar/grammar.test.ts | 16 ++++++++++++++++ 9 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.test.ts create mode 100644 packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.ts diff --git a/packages/app-vscode/package.json b/packages/app-vscode/package.json index 2ffbe6da84f..29c1978012f 100644 --- a/packages/app-vscode/package.json +++ b/packages/app-vscode/package.json @@ -971,7 +971,6 @@ "revealDefinition", "revealTypeDefinition", "reverseTargets", - "rewrapWithPairedDelimiter", "scrollToBottom", "scrollToCenter", "scrollToTop", @@ -987,7 +986,8 @@ "toggleLineBreakpoint", "toggleLineComment", "unfoldRegion", - "wrap" + "wrap", + "rewrap" ] }, { @@ -1048,7 +1048,8 @@ "toggleLineBreakpoint", "toggleLineComment", "unfoldRegion", - "wrap" + "wrap", + "rewrap" ], "description": "The cursorless command to run" }, diff --git a/packages/app-vscode/src/keyboard/KeyboardActionType.ts b/packages/app-vscode/src/keyboard/KeyboardActionType.ts index ffef180441f..eba9c1129b0 100644 --- a/packages/app-vscode/src/keyboard/KeyboardActionType.ts +++ b/packages/app-vscode/src/keyboard/KeyboardActionType.ts @@ -3,16 +3,18 @@ import { actionNames } from "@cursorless/lib-common"; // This file contains types defining the allowable identifiers for actions in // user keyboard config settings. It is a modified version of the default action -// identifiers from @cursorless/lib-common, with the addition of the "wrap" action -// that is designed to function like the "wrap" spoken form (ie use the same spoken -// form for both snippet and delimiter wrapping). +// identifiers from @cursorless/lib-common, with the addition of the "wrap" and +// "rewrap" actions that are designed to function like the "wrap" and "rewrap" +// spoken forms (ie use the same spoken form for both snippet and delimiter +// wrapping). -const extraKeyboardActionNames = ["wrap"] as const; +const extraKeyboardActionNames = ["wrap", "rewrap"] as const; const excludedKeyboardActionNames = [ "wrapWithPairedDelimiter", + "rewrapWithPairedDelimiter", "wrapWithSnippet", ] as const; -const complexKeyboardActionTypes = ["wrap"] as const; +const complexKeyboardActionTypes = ["wrap", "rewrap"] as const; type ExtraKeyboardActionType = (typeof extraKeyboardActionNames)[number]; type ExcludedKeyboardActionType = (typeof excludedKeyboardActionNames)[number]; diff --git a/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts b/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts index 0327f6c1458..48e8fe9375a 100644 --- a/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts +++ b/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts @@ -15,6 +15,7 @@ import type { TargetingMode, KeyboardCommandsTargeted, } from "./KeyboardCommandsTargeted"; +import { getPairedDelimiterCommandName } from "./getPairedDelimiterCommandName"; import type { ModalVscodeCommandDescriptor } from "./TokenTypes"; /** @@ -93,7 +94,7 @@ export class KeyboardCommandHandler { } await this.targeted.performActionOnTarget( (target) => ({ - name: "wrapWithPairedDelimiter", + name: getPairedDelimiterCommandName(actionDescriptor.actionId), target, left: delimiters[0], right: delimiters[1], @@ -132,6 +133,6 @@ interface DecoratedMarkArg { } interface WrapActionArg { - actionDescriptor: SpecificKeyboardActionDescriptor<"wrap">; + actionDescriptor: SpecificKeyboardActionDescriptor<"wrap" | "rewrap">; delimiter: SurroundingPairName; } diff --git a/packages/app-vscode/src/keyboard/KeyboardCommandsTargeted.ts b/packages/app-vscode/src/keyboard/KeyboardCommandsTargeted.ts index 092d7bf0e45..10ea24189b6 100644 --- a/packages/app-vscode/src/keyboard/KeyboardCommandsTargeted.ts +++ b/packages/app-vscode/src/keyboard/KeyboardCommandsTargeted.ts @@ -188,7 +188,6 @@ export class KeyboardCommandsTargeted { return this.performActionOnTarget( (target) => { switch (name) { - case "rewrapWithPairedDelimiter": case "insertSnippet": case "executeCommand": case "replace": diff --git a/packages/app-vscode/src/keyboard/TokenTypes.ts b/packages/app-vscode/src/keyboard/TokenTypes.ts index 31a7c05a8cb..768a481daa0 100644 --- a/packages/app-vscode/src/keyboard/TokenTypes.ts +++ b/packages/app-vscode/src/keyboard/TokenTypes.ts @@ -66,7 +66,7 @@ export interface TokenTypeValueMap { // action config section simpleAction: SimpleKeyboardActionDescriptor; - wrap: SpecificKeyboardActionDescriptor<"wrap">; + wrap: SpecificKeyboardActionDescriptor<"wrap" | "rewrap">; // misc config section targetingMode: "makeRange" | "makeVerticalRange" | "makeList"; diff --git a/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.test.ts b/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.test.ts new file mode 100644 index 00000000000..bca81028333 --- /dev/null +++ b/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.test.ts @@ -0,0 +1,18 @@ +import assert from "node:assert/strict"; +import { getPairedDelimiterCommandName } from "./getPairedDelimiterCommandName"; + +suite("getPairedDelimiterCommandName", () => { + test("wrap maps to wrapWithPairedDelimiter", () => { + assert.equal( + getPairedDelimiterCommandName("wrap"), + "wrapWithPairedDelimiter", + ); + }); + + test("rewrap maps to rewrapWithPairedDelimiter", () => { + assert.equal( + getPairedDelimiterCommandName("rewrap"), + "rewrapWithPairedDelimiter", + ); + }); +}); diff --git a/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.ts b/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.ts new file mode 100644 index 00000000000..a2b61f489b0 --- /dev/null +++ b/packages/app-vscode/src/keyboard/getPairedDelimiterCommandName.ts @@ -0,0 +1,17 @@ +/** + * Maps the keyboard "wrap" / "rewrap" action to the cursorless command that + * performs it with a paired delimiter. + * + * Kept free of `vscode` imports so it can be unit tested outside the extension + * host. + * + * @param actionId The keyboard action identifier, either `wrap` or `rewrap` + * @returns The command name to run on the target + */ +export function getPairedDelimiterCommandName( + actionId: "wrap" | "rewrap", +): "wrapWithPairedDelimiter" | "rewrapWithPairedDelimiter" { + return actionId === "rewrap" + ? "rewrapWithPairedDelimiter" + : "wrapWithPairedDelimiter"; +} diff --git a/packages/app-vscode/src/keyboard/getTokenTypeKeyMaps.ts b/packages/app-vscode/src/keyboard/getTokenTypeKeyMaps.ts index 325def73b77..17f8a85e9d6 100644 --- a/packages/app-vscode/src/keyboard/getTokenTypeKeyMaps.ts +++ b/packages/app-vscode/src/keyboard/getTokenTypeKeyMaps.ts @@ -49,7 +49,7 @@ export function getTokenTypeKeyMaps( transformActionDescriptor(value, simpleKeyboardActionNames), ), wrap: config.getTokenKeyMap("wrap", "action", (value) => - transformActionDescriptor(value, ["wrap"]), + transformActionDescriptor(value, ["wrap", "rewrap"]), ), // misc config section diff --git a/packages/app-vscode/src/keyboard/grammar/grammar.test.ts b/packages/app-vscode/src/keyboard/grammar/grammar.test.ts index bdad0ffc5cf..aad13a06ea7 100644 --- a/packages/app-vscode/src/keyboard/grammar/grammar.test.ts +++ b/packages/app-vscode/src/keyboard/grammar/grammar.test.ts @@ -162,6 +162,22 @@ const testCases: TestCase[] = [ type: "modifyTarget", }, }, + { + tokens: [ + { + type: "wrap", + value: { actionId: "rewrap", exitCursorlessMode: false }, + }, + { type: "pairedDelimiter", value: "parentheses" }, + ], + expected: { + arg: { + actionDescriptor: { actionId: "rewrap", exitCursorlessMode: false }, + delimiter: "parentheses", + }, + type: "performWrapActionOnTarget", + }, + }, { tokens: [ { From 29ba23b189e1e591237c2e477ab059a986bb0be3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:58:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts b/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts index 48e8fe9375a..99964072e83 100644 --- a/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts +++ b/packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts @@ -7,6 +7,7 @@ import type { } from "@cursorless/lib-common"; import { pairedDelimiterReferences } from "@cursorless/lib-common"; import type { HatColor, HatShape } from "../ide/vscode/hatStyles.types"; +import { getPairedDelimiterCommandName } from "./getPairedDelimiterCommandName"; import type { SimpleKeyboardActionDescriptor, SpecificKeyboardActionDescriptor, @@ -15,7 +16,6 @@ import type { TargetingMode, KeyboardCommandsTargeted, } from "./KeyboardCommandsTargeted"; -import { getPairedDelimiterCommandName } from "./getPairedDelimiterCommandName"; import type { ModalVscodeCommandDescriptor } from "./TokenTypes"; /**