Skip to content

Commit

Permalink
move definition of which actions exit cursorless mode to the config (c…
Browse files Browse the repository at this point in the history
…ursorless-dev#2174)

Fixes cursorless-dev#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 <755842+pokey@users.noreply.github.com>
  • Loading branch information
3 people authored and Barry Jaspan committed Jan 22, 2024
1 parent 760452a commit 046f787
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 181 deletions.
183 changes: 128 additions & 55 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -864,61 +864,134 @@
"description": "Define modal keybindings for actions",
"type": "object",
"additionalProperties": {
"type": "string",
"enum": [
"callAsFunction",
"clearAndSetSelection",
"copyToClipboard",
"cutToClipboard",
"deselect",
"editNew",
"editNewLineAfter",
"editNewLineBefore",
"executeCommand",
"extractVariable",
"findInDocument",
"findInWorkspace",
"foldRegion",
"followLink",
"generateSnippet",
"getText",
"highlight",
"indentLine",
"insertCopyAfter",
"insertCopyBefore",
"insertEmptyLineAfter",
"insertEmptyLineBefore",
"insertEmptyLinesAround",
"insertSnippet",
"moveToTarget",
"outdentLine",
"pasteFromClipboard",
"randomizeTargets",
"remove",
"rename",
"replace",
"replaceWithTarget",
"revealDefinition",
"revealTypeDefinition",
"reverseTargets",
"rewrapWithPairedDelimiter",
"scrollToBottom",
"scrollToCenter",
"scrollToTop",
"setSelection",
"setSelectionAfter",
"setSelectionBefore",
"showDebugHover",
"showHover",
"showQuickFix",
"showReferences",
"sortTargets",
"swapTargets",
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"wrapWithPairedDelimiter",
"wrapWithSnippet"
"anyOf": [
{
"type": "string",
"enum": [
"callAsFunction",
"clearAndSetSelection",
"copyToClipboard",
"cutToClipboard",
"deselect",
"editNew",
"editNewLineAfter",
"editNewLineBefore",
"executeCommand",
"extractVariable",
"findInDocument",
"findInWorkspace",
"foldRegion",
"followLink",
"generateSnippet",
"getText",
"highlight",
"indentLine",
"insertCopyAfter",
"insertCopyBefore",
"insertEmptyLineAfter",
"insertEmptyLineBefore",
"insertEmptyLinesAround",
"insertSnippet",
"moveToTarget",
"outdentLine",
"pasteFromClipboard",
"randomizeTargets",
"remove",
"rename",
"replace",
"replaceWithTarget",
"revealDefinition",
"revealTypeDefinition",
"reverseTargets",
"rewrapWithPairedDelimiter",
"scrollToBottom",
"scrollToCenter",
"scrollToTop",
"setSelection",
"setSelectionAfter",
"setSelectionBefore",
"showDebugHover",
"showHover",
"showQuickFix",
"showReferences",
"sortTargets",
"swapTargets",
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"wrap"
]
},
{
"type": "object",
"properties": {
"actionId": {
"type": "string",
"enum": [
"callAsFunction",
"clearAndSetSelection",
"copyToClipboard",
"cutToClipboard",
"deselect",
"editNew",
"editNewLineAfter",
"editNewLineBefore",
"executeCommand",
"extractVariable",
"findInDocument",
"findInWorkspace",
"foldRegion",
"followLink",
"generateSnippet",
"getText",
"highlight",
"indentLine",
"insertCopyAfter",
"insertCopyBefore",
"insertEmptyLineAfter",
"insertEmptyLineBefore",
"insertEmptyLinesAround",
"insertSnippet",
"moveToTarget",
"outdentLine",
"pasteFromClipboard",
"randomizeTargets",
"remove",
"rename",
"replace",
"replaceWithTarget",
"revealDefinition",
"revealTypeDefinition",
"reverseTargets",
"rewrapWithPairedDelimiter",
"scrollToBottom",
"scrollToCenter",
"scrollToTop",
"setSelection",
"setSelectionAfter",
"setSelectionBefore",
"showDebugHover",
"showHover",
"showQuickFix",
"showReferences",
"sortTargets",
"swapTargets",
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"wrap"
],
"description": "The cursorless command to run"
},
"exitCursorlessMode": {
"type": "boolean",
"description": "Indicates whether the command should exit cursorless mode after it is run, defaults false."
}
},
"required": [
"actionId"
]
}
]
}
},
Expand Down
13 changes: 13 additions & 0 deletions packages/cursorless-vscode/src/keyboard/KeyboardActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ export type SimpleKeyboardActionType = Exclude<
KeyboardActionType,
ComplexKeyboardActionType
>;

export type SpecificKeyboardActionDescriptor<T extends KeyboardActionType> = {
actionId: T;
exitCursorlessMode: boolean;
};

export type PolymorphicKeyboardActionDescriptor =
| KeyboardActionType
| SpecificKeyboardActionDescriptor<KeyboardActionType>;

export type SimpleKeyboardActionDescriptor =
SpecificKeyboardActionDescriptor<SimpleKeyboardActionType>;

export type KeyboardActionType =
| Exclude<ActionType, ExcludedKeyboardActionType>
| ExtraKeyboardActionType;
Expand Down
34 changes: 21 additions & 13 deletions packages/cursorless-vscode/src/keyboard/KeyboardCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Modifier, SurroundingPairName } from "@cursorless/common";
import * as vscode from "vscode";
import { HatColor, HatShape } from "../ide/vscode/hatStyles.types";
import { SimpleKeyboardActionType } from "./KeyboardActionType";
import {
SimpleKeyboardActionDescriptor,
SpecificKeyboardActionDescriptor,
} from "./KeyboardActionType";
import KeyboardCommandsTargeted from "./KeyboardCommandsTargeted";
import { ModalVscodeCommandDescriptor } from "./TokenTypes";
import { surroundingPairsDelimiters } from "@cursorless/cursorless-engine";
import { isString } from "lodash";

/**
* This class defines the keyboard commands available to our modal keyboard
Expand Down Expand Up @@ -65,21 +69,24 @@ export class KeyboardCommandHandler {
}

performSimpleActionOnTarget({
actionName,
actionDescriptor,
}: {
actionName: SimpleKeyboardActionType;
actionDescriptor: SimpleKeyboardActionDescriptor;
}) {
this.targeted.performSimpleActionOnTarget(actionName);
this.targeted.performSimpleActionOnTarget(actionDescriptor);
}

performWrapActionOnTarget({ delimiter }: { delimiter: SurroundingPairName }) {
performWrapActionOnTarget({ actionDescriptor, delimiter }: WrapActionArg) {
const [left, right] = surroundingPairsDelimiters[delimiter]!;
this.targeted.performActionOnTarget((target) => ({
name: "wrapWithPairedDelimiter",
target,
left,
right,
}));
this.targeted.performActionOnTarget(
(target) => ({
name: "wrapWithPairedDelimiter",
target,
left,
right,
}),
actionDescriptor,
);
}

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

function isString(input: any): input is string {
return typeof input === "string" || input instanceof String;
interface WrapActionArg {
actionDescriptor: SpecificKeyboardActionDescriptor<"wrap">;
delimiter: SurroundingPairName;
}
Loading

0 comments on commit 046f787

Please sign in to comment.