Skip to content

Commit

Permalink
Added grand scope
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Dec 13, 2023
1 parent c6f5600 commit b388490
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
18 changes: 17 additions & 1 deletion cursorless-talon/src/modifiers/simple_scope_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,23 @@
)
def cursorless_simple_scope_modifier(m) -> dict[str, Any]:
"""Containing scope, every scope, etc"""
if hasattr(m, "cursorless_simple_scope_modifier"):
modifier = m.cursorless_simple_scope_modifier

if modifier == "every":
return {
"type": "everyScope",
"scopeType": m.cursorless_scope_type,
}

if modifier == "grand":
return {
"type": "containingScope",
"scopeType": m.cursorless_scope_type,
"ancestorIndex": 1,
}

return {
"type": "everyScope" if m[0] == "every" else "containingScope",
"type": "containingScope",
"scopeType": m.cursorless_scope_type,
}
2 changes: 1 addition & 1 deletion cursorless-talon/src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"its": "inferPreviousMark",
"visible": "visible"
},
"simple_scope_modifier": { "every": "every" },
"simple_scope_modifier": { "every": "every", "grand": "grand" },
"interior_modifier": {
"inside": "interiorOnly"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export class PrimitiveTargetSpokenFormGenerator {
throw new NoSpokenFormError(`Modifier '${modifier.type}'`);

case "containingScope":
if (modifier.ancestorIndex != null) {
if (modifier.ancestorIndex === 1) {
return [
this.spokenFormMap.modifierExtra.grandScope,
this.handleScopeType(modifier.scopeType),
];
}
throw new NoSpokenFormError(
`Modifier '${modifier.type}' with ancestor index != 1`,
);
}
return [this.handleScopeType(modifier.scopeType)];

case "everyScope":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function getContainingScopeTarget(
scope = expandFromPosition(
scopeHandler,
editor,
scope.domain.end,
"forward",
scope.domain.start,
"backward",
ancestorIndex - 1,
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-engine/src/spokenForms/SpokenFormType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ModifierExtra =
| "previous"
| "next"
| "forward"
| "backward";
| "backward"
| "grandScope";

export type SpokenFormType = keyof SpokenFormMapKeyTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
next: "next",
forward: "forward",
backward: "backward",
grandScope: "grand",
},

customRegex: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: javascript
command:
version: 6
spokenForm: change grand state
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
ancestorIndex: 1
usePrePhraseSnapshot: true
initialState:
documentContents: |-
function myFunk() {
const value = 2
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: python
command:
version: 6
spokenForm: change grand state
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
ancestorIndex: 1
usePrePhraseSnapshot: true
initialState:
documentContents: |-
def my_funk():
value = 2
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}

0 comments on commit b388490

Please sign in to comment.