Skip to content

Commit

Permalink
Add keyboard special target (#2168)
Browse files Browse the repository at this point in the history
- Depends on #2170

## Checklist

- [x] 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
  • Loading branch information
pokey authored Jan 15, 2024
1 parent f2c9f4a commit 6f01c31
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 87 deletions.
1 change: 1 addition & 0 deletions packages/common/src/StoredTargetKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const storedTargetKeys = [
"that",
"source",
"instanceReference",
"keyboard",
] as const;
export type StoredTargetKey = (typeof storedTargetKeys)[number];
1 change: 1 addition & 0 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const simpleActionNames = [
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
"private.setKeyboardTarget",
"private.showParseTree",
"private.getTargets",
] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export interface ThatMark {
type: "that";
}

export interface KeyboardMark {
type: "keyboard";
}

export interface SourceMark {
type: "source";
}
Expand Down Expand Up @@ -69,6 +73,7 @@ export type PartialMark =
| CursorMark
| ThatMark
| SourceMark
| KeyboardMark
| DecoratedSymbolMark
| NothingMark
| LineNumberMark
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/CommandHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function sanitizeActionInPlace(action: ActionDescriptor): void {
case "swapTargets":
case "wrapWithPairedDelimiter":
case "findInDocument":
case "private.setKeyboardTarget":
break;

default: {
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class Actions implements ActionRecord {
scrollToBottom = new ScrollToBottom();
scrollToCenter = new ScrollToCenter();
scrollToTop = new ScrollToTop();
["private.setKeyboardTarget"] = new SetSpecialTarget("keyboard");
["experimental.setInstanceReference"] = new SetSpecialTarget(
"instanceReference",
);
Expand Down
5 changes: 5 additions & 0 deletions packages/cursorless-engine/src/actions/actions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export interface ActionReturnValue {
* to determine either the range for "every", or the start point for "next"
*/
instanceReferenceTargets?: Target[];

/**
* A list of targets that become the active keybaord targets
*/
keyboardTargets?: Target[];
}

export interface SimpleAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class CommandRunnerImpl implements CommandRunner {
sourceSelections: newSourceSelections,
sourceTargets: newSourceTargets,
instanceReferenceTargets: newInstanceReferenceTargets,
keyboardTargets: newKeyboardTargets,
} = await this.runAction(action);

this.storedTargets.set(
Expand All @@ -65,6 +66,7 @@ export class CommandRunnerImpl implements CommandRunner {
constructStoredTarget(newSourceTargets, newSourceSelections),
);
this.storedTargets.set("instanceReference", newInstanceReferenceTargets);
this.storedTargets.set("keyboard", newKeyboardTargets);

return returnValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const actions = {
getText: null,
replace: null,
["private.getTargets"]: null,
["private.setKeyboardTarget"]: null,

// These actions are implemented talon-side, usually using `getText` followed
// by some other action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const marks = {
source: "source",
nothing: "nothing",

keyboard: null,
explicit: null,
decoratedSymbol: null,
lineNumber: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class SpokenFormGenerator {
case "replace":
case "executeCommand":
case "private.getTargets":
case "private.setKeyboardTarget":
throw new NoSpokenFormError(`Action '${action.name}'`);

case "replaceWithTarget":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class PrimitiveTargetSpokenFormGenerator {
throw Error(`Mark '${mark.type}' is not fully implemented`);
}
case "explicit":
case "keyboard":
throw new NoSpokenFormError(`Mark '${mark.type}'`);

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class MarkStageFactoryImpl implements MarkStageFactory {
return new CursorStage(mark);
case "that":
case "source":
case "keyboard":
return new StoredTargetStage(this.storedTargets, mark.type);
case "decoratedSymbol":
return new DecoratedSymbolStage(this.readableHatMap, mark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ suite("Basic keyboard test", async function () {

test("Don't take keyboard control on startup", () => checkKeyboardStartup());
test("Basic keyboard test", () => basic());
test("No automatic token expansion", () => noAutomaticTokenExpansion());
test("Run vscode command", () => vscodeCommand());
test("Check that entering and leaving mode is no-op", () =>
enterAndLeaveIsNoOp());
Expand Down Expand Up @@ -65,6 +66,22 @@ async function basic() {
assert.equal(editor.document.getText().trim(), "a");
}

async function noAutomaticTokenExpansion() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor("aaa");
await hatTokenMap.allocateHats();

editor.selection = new vscode.Selection(0, 3, 0, 3);

await vscode.commands.executeCommand("cursorless.keyboard.modal.modeOn");

// "pour"
await typeText("ao");

assert.isTrue(editor.selection.isEqual(new vscode.Selection(1, 0, 1, 0)));
}

async function vscodeCommand() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class KeyboardCommandHandler {
}: {
actionName: SimpleKeyboardActionType;
}) {
this.targeted.performActionOnTarget(actionName);
this.targeted.performSimpleActionOnTarget(actionName);
}

modifyTargetContainingScope(arg: { scopeType: ScopeType }) {
Expand Down
Loading

0 comments on commit 6f01c31

Please sign in to comment.