Skip to content

Commit 21b5868

Browse files
Added get targets action (#1821)
Fixes #1820 ```talon info <user.cursorless_target>: target_info = user.private_cursorless_get_targets(cursorless_target) print(target_info) ``` ```python def private_cursorless_get_targets(target: Any) -> list[dict]: """Get information about Cursorless target""" return actions.user.private_cursorless_command_get( { "name": "private.getTargets", "target": target, } ) ``` ```json [ {"contentRange": {"start": {"line": 71, "character": 23}, "end": {"line": 71, "character": 53}}} ] ``` ## 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
1 parent 2bc7a94 commit 21b5868

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

packages/common/src/types/command/ActionDescriptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const simpleActionNames = [
4646
"toggleLineBreakpoint",
4747
"toggleLineComment",
4848
"unfoldRegion",
49+
"private.getTargets",
4950
] as const;
5051

5152
const complexActionNames = [

packages/cursorless-engine/src/actions/Actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ExecuteCommand from "./ExecuteCommand";
1212
import { FindInWorkspace } from "./Find";
1313
import FollowLink from "./FollowLink";
1414
import GenerateSnippet from "./GenerateSnippet";
15+
import GetTargets from "./GetTargets";
1516
import GetText from "./GetText";
1617
import Highlight from "./Highlight";
1718
import {
@@ -144,4 +145,5 @@ export class Actions implements ActionRecord {
144145
this.snippets,
145146
this.modifierStageFactory,
146147
);
148+
["private.getTargets"] = new GetTargets();
147149
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Target } from "../typings/target.types";
2+
import { ActionReturnValue, SimpleAction } from "./actions.types";
3+
4+
export default class GetTargets implements SimpleAction {
5+
constructor() {
6+
this.run = this.run.bind(this);
7+
}
8+
9+
async run(targets: Target[]): Promise<ActionReturnValue> {
10+
return {
11+
returnValue: targets.map(({ contentRange }) => ({
12+
contentRange,
13+
})),
14+
thatTargets: targets,
15+
};
16+
}
17+
}

packages/cursorless-engine/src/generateSpokenForm/defaultSpokenForms/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const actions = {
6060
executeCommand: null,
6161
getText: null,
6262
replace: null,
63+
["private.getTargets"]: null,
6364

6465
// These actions are implemented talon-side, usually using `getText` followed
6566
// by some other action.

packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function generateSpokenFormComponents(
5656
case "getText":
5757
case "replace":
5858
case "executeCommand":
59+
case "private.getTargets":
5960
throw new NoSpokenFormError(`Action '${action.name}'`);
6061

6162
case "replaceWithTarget":
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
languageId: plaintext
2+
command:
3+
version: 6
4+
spokenForm: get targets bat and cap
5+
action:
6+
name: private.getTargets
7+
target:
8+
type: list
9+
elements:
10+
- type: primitive
11+
mark: {type: decoratedSymbol, symbolColor: default, character: b}
12+
- type: primitive
13+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
14+
usePrePhraseSnapshot: true
15+
spokenFormError: Action 'private.getTargets'
16+
initialState:
17+
documentContents: a b c d
18+
selections:
19+
- anchor: {line: 0, character: 0}
20+
active: {line: 0, character: 0}
21+
marks:
22+
default.b:
23+
start: {line: 0, character: 2}
24+
end: {line: 0, character: 3}
25+
default.c:
26+
start: {line: 0, character: 4}
27+
end: {line: 0, character: 5}
28+
finalState:
29+
documentContents: a b c d
30+
selections:
31+
- anchor: {line: 0, character: 0}
32+
active: {line: 0, character: 0}
33+
thatMark:
34+
- type: UntypedTarget
35+
contentRange:
36+
start: {line: 0, character: 2}
37+
end: {line: 0, character: 3}
38+
isReversed: false
39+
hasExplicitRange: false
40+
- type: UntypedTarget
41+
contentRange:
42+
start: {line: 0, character: 4}
43+
end: {line: 0, character: 5}
44+
isReversed: false
45+
hasExplicitRange: false
46+
returnValue:
47+
- contentRange:
48+
start: {line: 0, character: 2}
49+
end: {line: 0, character: 3}
50+
- contentRange:
51+
start: {line: 0, character: 4}
52+
end: {line: 0, character: 5}

0 commit comments

Comments
 (0)