Skip to content

Commit 08abb7f

Browse files
josharianpre-commit-ci-lite[bot]pokey
authored
move definition of which actions exit cursorless mode to the config (#2174)
Fixes #2117 ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <[email protected]>
1 parent 9b98f53 commit 08abb7f

File tree

10 files changed

+351
-181
lines changed

10 files changed

+351
-181
lines changed

packages/cursorless-vscode/package.json

Lines changed: 128 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -864,61 +864,134 @@
864864
"description": "Define modal keybindings for actions",
865865
"type": "object",
866866
"additionalProperties": {
867-
"type": "string",
868-
"enum": [
869-
"callAsFunction",
870-
"clearAndSetSelection",
871-
"copyToClipboard",
872-
"cutToClipboard",
873-
"deselect",
874-
"editNew",
875-
"editNewLineAfter",
876-
"editNewLineBefore",
877-
"executeCommand",
878-
"extractVariable",
879-
"findInDocument",
880-
"findInWorkspace",
881-
"foldRegion",
882-
"followLink",
883-
"generateSnippet",
884-
"getText",
885-
"highlight",
886-
"indentLine",
887-
"insertCopyAfter",
888-
"insertCopyBefore",
889-
"insertEmptyLineAfter",
890-
"insertEmptyLineBefore",
891-
"insertEmptyLinesAround",
892-
"insertSnippet",
893-
"moveToTarget",
894-
"outdentLine",
895-
"pasteFromClipboard",
896-
"randomizeTargets",
897-
"remove",
898-
"rename",
899-
"replace",
900-
"replaceWithTarget",
901-
"revealDefinition",
902-
"revealTypeDefinition",
903-
"reverseTargets",
904-
"rewrapWithPairedDelimiter",
905-
"scrollToBottom",
906-
"scrollToCenter",
907-
"scrollToTop",
908-
"setSelection",
909-
"setSelectionAfter",
910-
"setSelectionBefore",
911-
"showDebugHover",
912-
"showHover",
913-
"showQuickFix",
914-
"showReferences",
915-
"sortTargets",
916-
"swapTargets",
917-
"toggleLineBreakpoint",
918-
"toggleLineComment",
919-
"unfoldRegion",
920-
"wrapWithPairedDelimiter",
921-
"wrapWithSnippet"
867+
"anyOf": [
868+
{
869+
"type": "string",
870+
"enum": [
871+
"callAsFunction",
872+
"clearAndSetSelection",
873+
"copyToClipboard",
874+
"cutToClipboard",
875+
"deselect",
876+
"editNew",
877+
"editNewLineAfter",
878+
"editNewLineBefore",
879+
"executeCommand",
880+
"extractVariable",
881+
"findInDocument",
882+
"findInWorkspace",
883+
"foldRegion",
884+
"followLink",
885+
"generateSnippet",
886+
"getText",
887+
"highlight",
888+
"indentLine",
889+
"insertCopyAfter",
890+
"insertCopyBefore",
891+
"insertEmptyLineAfter",
892+
"insertEmptyLineBefore",
893+
"insertEmptyLinesAround",
894+
"insertSnippet",
895+
"moveToTarget",
896+
"outdentLine",
897+
"pasteFromClipboard",
898+
"randomizeTargets",
899+
"remove",
900+
"rename",
901+
"replace",
902+
"replaceWithTarget",
903+
"revealDefinition",
904+
"revealTypeDefinition",
905+
"reverseTargets",
906+
"rewrapWithPairedDelimiter",
907+
"scrollToBottom",
908+
"scrollToCenter",
909+
"scrollToTop",
910+
"setSelection",
911+
"setSelectionAfter",
912+
"setSelectionBefore",
913+
"showDebugHover",
914+
"showHover",
915+
"showQuickFix",
916+
"showReferences",
917+
"sortTargets",
918+
"swapTargets",
919+
"toggleLineBreakpoint",
920+
"toggleLineComment",
921+
"unfoldRegion",
922+
"wrap"
923+
]
924+
},
925+
{
926+
"type": "object",
927+
"properties": {
928+
"actionId": {
929+
"type": "string",
930+
"enum": [
931+
"callAsFunction",
932+
"clearAndSetSelection",
933+
"copyToClipboard",
934+
"cutToClipboard",
935+
"deselect",
936+
"editNew",
937+
"editNewLineAfter",
938+
"editNewLineBefore",
939+
"executeCommand",
940+
"extractVariable",
941+
"findInDocument",
942+
"findInWorkspace",
943+
"foldRegion",
944+
"followLink",
945+
"generateSnippet",
946+
"getText",
947+
"highlight",
948+
"indentLine",
949+
"insertCopyAfter",
950+
"insertCopyBefore",
951+
"insertEmptyLineAfter",
952+
"insertEmptyLineBefore",
953+
"insertEmptyLinesAround",
954+
"insertSnippet",
955+
"moveToTarget",
956+
"outdentLine",
957+
"pasteFromClipboard",
958+
"randomizeTargets",
959+
"remove",
960+
"rename",
961+
"replace",
962+
"replaceWithTarget",
963+
"revealDefinition",
964+
"revealTypeDefinition",
965+
"reverseTargets",
966+
"rewrapWithPairedDelimiter",
967+
"scrollToBottom",
968+
"scrollToCenter",
969+
"scrollToTop",
970+
"setSelection",
971+
"setSelectionAfter",
972+
"setSelectionBefore",
973+
"showDebugHover",
974+
"showHover",
975+
"showQuickFix",
976+
"showReferences",
977+
"sortTargets",
978+
"swapTargets",
979+
"toggleLineBreakpoint",
980+
"toggleLineComment",
981+
"unfoldRegion",
982+
"wrap"
983+
],
984+
"description": "The cursorless command to run"
985+
},
986+
"exitCursorlessMode": {
987+
"type": "boolean",
988+
"description": "Indicates whether the command should exit cursorless mode after it is run, defaults false."
989+
}
990+
},
991+
"required": [
992+
"actionId"
993+
]
994+
}
922995
]
923996
}
924997
},

packages/cursorless-vscode/src/keyboard/KeyboardActionType.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ export type SimpleKeyboardActionType = Exclude<
2020
KeyboardActionType,
2121
ComplexKeyboardActionType
2222
>;
23+
24+
export type SpecificKeyboardActionDescriptor<T extends KeyboardActionType> = {
25+
actionId: T;
26+
exitCursorlessMode: boolean;
27+
};
28+
29+
export type PolymorphicKeyboardActionDescriptor =
30+
| KeyboardActionType
31+
| SpecificKeyboardActionDescriptor<KeyboardActionType>;
32+
33+
export type SimpleKeyboardActionDescriptor =
34+
SpecificKeyboardActionDescriptor<SimpleKeyboardActionType>;
35+
2336
export type KeyboardActionType =
2437
| Exclude<ActionType, ExcludedKeyboardActionType>
2538
| ExtraKeyboardActionType;

packages/cursorless-vscode/src/keyboard/KeyboardCommandHandler.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { Modifier, SurroundingPairName } from "@cursorless/common";
22
import * as vscode from "vscode";
33
import { HatColor, HatShape } from "../ide/vscode/hatStyles.types";
4-
import { SimpleKeyboardActionType } from "./KeyboardActionType";
4+
import {
5+
SimpleKeyboardActionDescriptor,
6+
SpecificKeyboardActionDescriptor,
7+
} from "./KeyboardActionType";
58
import KeyboardCommandsTargeted from "./KeyboardCommandsTargeted";
69
import { ModalVscodeCommandDescriptor } from "./TokenTypes";
710
import { surroundingPairsDelimiters } from "@cursorless/cursorless-engine";
11+
import { isString } from "lodash";
812

913
/**
1014
* This class defines the keyboard commands available to our modal keyboard
@@ -65,21 +69,24 @@ export class KeyboardCommandHandler {
6569
}
6670

6771
performSimpleActionOnTarget({
68-
actionName,
72+
actionDescriptor,
6973
}: {
70-
actionName: SimpleKeyboardActionType;
74+
actionDescriptor: SimpleKeyboardActionDescriptor;
7175
}) {
72-
this.targeted.performSimpleActionOnTarget(actionName);
76+
this.targeted.performSimpleActionOnTarget(actionDescriptor);
7377
}
7478

75-
performWrapActionOnTarget({ delimiter }: { delimiter: SurroundingPairName }) {
79+
performWrapActionOnTarget({ actionDescriptor, delimiter }: WrapActionArg) {
7680
const [left, right] = surroundingPairsDelimiters[delimiter]!;
77-
this.targeted.performActionOnTarget((target) => ({
78-
name: "wrapWithPairedDelimiter",
79-
target,
80-
left,
81-
right,
82-
}));
81+
this.targeted.performActionOnTarget(
82+
(target) => ({
83+
name: "wrapWithPairedDelimiter",
84+
target,
85+
left,
86+
right,
87+
}),
88+
actionDescriptor,
89+
);
8390
}
8491

8592
modifyTarget({ modifier }: { modifier: Modifier }) {
@@ -95,6 +102,7 @@ interface DecoratedMarkArg {
95102
mode: "replace" | "extend" | "append";
96103
}
97104

98-
function isString(input: any): input is string {
99-
return typeof input === "string" || input instanceof String;
105+
interface WrapActionArg {
106+
actionDescriptor: SpecificKeyboardActionDescriptor<"wrap">;
107+
delimiter: SurroundingPairName;
100108
}

0 commit comments

Comments
 (0)