Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/app-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@
"revealDefinition",
"revealTypeDefinition",
"reverseTargets",
"rewrapWithPairedDelimiter",
"scrollToBottom",
"scrollToCenter",
"scrollToTop",
Expand All @@ -987,7 +986,8 @@
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"wrap"
"wrap",
"rewrap"
]
},
{
Expand Down Expand Up @@ -1048,7 +1048,8 @@
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"wrap"
"wrap",
"rewrap"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the stale ID from the structured action enum

When a user chooses the object-form keybinding { "actionId": "rewrapWithPairedDelimiter" }, this enum still marks it valid at line 1035, but KeyboardActionType.ts now excludes that ID and getTokenTypeKeyMaps accepts only wrap/rewrap, so KeyboardConfig.getTokenKeyMap silently drops the binding. The string branch was corrected in this commit; remove the old ID from this object branch too so VS Code does not advertise a configuration that creates a dead key.

Useful? React with 👍 / 👎.

],
"description": "The cursorless command to run"
},
Expand Down
12 changes: 7 additions & 5 deletions packages/app-vscode/src/keyboard/KeyboardActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions packages/app-vscode/src/keyboard/KeyboardCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -132,6 +133,6 @@ interface DecoratedMarkArg {
}

interface WrapActionArg {
actionDescriptor: SpecificKeyboardActionDescriptor<"wrap">;
actionDescriptor: SpecificKeyboardActionDescriptor<"wrap" | "rewrap">;
delimiter: SurroundingPairName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export class KeyboardCommandsTargeted {
return this.performActionOnTarget(
(target) => {
switch (name) {
case "rewrapWithPairedDelimiter":
case "insertSnippet":
case "executeCommand":
case "replace":
Expand Down
2 changes: 1 addition & 1 deletion packages/app-vscode/src/keyboard/TokenTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
);
});
});
Original file line number Diff line number Diff line change
@@ -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";
}
2 changes: 1 addition & 1 deletion packages/app-vscode/src/keyboard/getTokenTypeKeyMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions packages/app-vscode/src/keyboard/grammar/grammar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Loading