Skip to content

Commit ab072ee

Browse files
Support grand grand scope (#2773)
Allows you to say grand multiple times. eg `"take grand grand state"` Fixes #2152 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] 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) - [x] I have not broken the cheatsheet
1 parent 058d545 commit ab072ee

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

cursorless-talon/src/modifiers/simple_scope_modifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@mod.capture(
2626
rule=(
27-
"[{user.cursorless_every_scope_modifier} | {user.cursorless_ancestor_scope_modifier}] "
27+
"[{user.cursorless_every_scope_modifier} | {user.cursorless_ancestor_scope_modifier}+] "
2828
"<user.cursorless_scope_type>"
2929
),
3030
)
@@ -40,7 +40,7 @@ def cursorless_simple_scope_modifier(m) -> dict[str, Any]:
4040
return {
4141
"type": "containingScope",
4242
"scopeType": m.cursorless_scope_type,
43-
"ancestorIndex": 1,
43+
"ancestorIndex": len(m.cursorless_ancestor_scope_modifier_list),
4444
}
4545

4646
if settings.get("user.private_cursorless_use_preferred_scope"):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: javascript
2+
command:
3+
version: 7
4+
spokenForm: change grand grand state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
ancestorIndex: 2
13+
usePrePhraseSnapshot: false
14+
initialState:
15+
documentContents: |-
16+
class MyClass {
17+
myFunk() {
18+
console.log("");
19+
}
20+
}
21+
selections:
22+
- anchor: {line: 2, character: 8}
23+
active: {line: 2, character: 8}
24+
marks: {}
25+
finalState:
26+
documentContents: ""
27+
selections:
28+
- anchor: {line: 0, character: 0}
29+
active: {line: 0, character: 0}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ export class PrimitiveTargetSpokenFormGenerator {
5252
if (modifier.ancestorIndex == null || modifier.ancestorIndex === 0) {
5353
return this.handleScopeType(modifier.scopeType);
5454
}
55-
if (modifier.ancestorIndex === 1) {
56-
return [
55+
return [
56+
new Array(modifier.ancestorIndex).fill(
5757
this.spokenFormMap.modifierExtra.ancestor,
58-
this.handleScopeType(modifier.scopeType),
59-
];
60-
}
61-
throw new NoSpokenFormError(
62-
`Modifier '${modifier.type}' with ancestor index ${modifier.ancestorIndex}`,
63-
);
58+
),
59+
this.handleScopeType(modifier.scopeType),
60+
];
6461

6562
case "everyScope":
6663
return [

packages/cursorless-org-docs/src/docs/user/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ The modifier `"grand"` can be used to select the parent of the containing syntac
233233
- `"take grand statement air"`
234234
- `"take grand funk air"`
235235

236-
For example, the command `"take grand statement [blue] air"` will select that parent statement of the statement containing the token with a blue hat over the letter 'a'.
236+
For example, the command `"take grand statement [blue] air"` will select the parent statement of the statement containing the token with a blue hat over the letter 'a'.
237+
238+
You can also repeat `"grand"` multiple times.
239+
240+
For example, the command `"take grand grand statement [blue] air"` will select the parent statement of the parent statement of the statement containing the token with a blue hat over the letter 'a'.
237241

238242
##### Sub-token modifiers
239243

0 commit comments

Comments
 (0)