Skip to content

Commit

Permalink
Support grand grand scope (#2773)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AndreasArvidsson authored Jan 26, 2025
1 parent 058d545 commit ab072ee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cursorless-talon/src/modifiers/simple_scope_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@mod.capture(
rule=(
"[{user.cursorless_every_scope_modifier} | {user.cursorless_ancestor_scope_modifier}] "
"[{user.cursorless_every_scope_modifier} | {user.cursorless_ancestor_scope_modifier}+] "
"<user.cursorless_scope_type>"
),
)
Expand All @@ -40,7 +40,7 @@ def cursorless_simple_scope_modifier(m) -> dict[str, Any]:
return {
"type": "containingScope",
"scopeType": m.cursorless_scope_type,
"ancestorIndex": 1,
"ancestorIndex": len(m.cursorless_ancestor_scope_modifier_list),
}

if settings.get("user.private_cursorless_use_preferred_scope"):
Expand Down
29 changes: 29 additions & 0 deletions data/fixtures/recorded/containingScope/changeGrandGrandState.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: javascript
command:
version: 7
spokenForm: change grand grand state
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
ancestorIndex: 2
usePrePhraseSnapshot: false
initialState:
documentContents: |-
class MyClass {
myFunk() {
console.log("");
}
}
selections:
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ export class PrimitiveTargetSpokenFormGenerator {
if (modifier.ancestorIndex == null || modifier.ancestorIndex === 0) {
return this.handleScopeType(modifier.scopeType);
}
if (modifier.ancestorIndex === 1) {
return [
return [
new Array(modifier.ancestorIndex).fill(
this.spokenFormMap.modifierExtra.ancestor,
this.handleScopeType(modifier.scopeType),
];
}
throw new NoSpokenFormError(
`Modifier '${modifier.type}' with ancestor index ${modifier.ancestorIndex}`,
);
),
this.handleScopeType(modifier.scopeType),
];

case "everyScope":
return [
Expand Down
6 changes: 5 additions & 1 deletion packages/cursorless-org-docs/src/docs/user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ The modifier `"grand"` can be used to select the parent of the containing syntac
- `"take grand statement air"`
- `"take grand funk air"`

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'.
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'.

You can also repeat `"grand"` multiple times.

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'.

##### Sub-token modifiers

Expand Down

0 comments on commit ab072ee

Please sign in to comment.