Skip to content

Commit 0b86df9

Browse files
authored
Add includeDescendantScopes field to scope handlers (#1647)
- Required by #1650 - Note that we have no tests here, but it is tested in #1653 ## Checklist - [ ] 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 d75bd2f commit 0b86df9

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const DEFAULT_REQUIREMENTS: Omit<ScopeIteratorRequirements, "distalPosition"> =
1414
containment: null,
1515
allowAdjacentScopes: false,
1616
skipAncestorScopes: false,
17+
includeDescendantScopes: false,
1718
};
1819

1920
/**

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/scopeHandler.types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,17 @@ export interface ScopeIteratorRequirements {
149149
* @default false
150150
*/
151151
skipAncestorScopes: boolean;
152+
153+
/**
154+
* Indicates whether the ScopeHandler should yield a scope if it is a
155+
* descendant of any scope that has been previously yielded.
156+
*
157+
* - `true` means that descendant scopes of any previously yielded scope will
158+
* be yielded.
159+
* - `false` means that descendant scopes of any previously yielded scope will
160+
* not be yielded.
161+
*
162+
* @default false
163+
*/
164+
includeDescendantScopes: boolean;
152165
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/shouldYieldScope.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ export function shouldYieldScope(
3131
checkRequirements(initialPosition, requirements, previousScope, scope) &&
3232
// Note that we're using `currentPosition` instead of `initialPosition`
3333
// below, because we want to filter out scopes that are strictly contained
34-
// by previous scopes.
34+
// by previous scopes. However, if we want to include descendant scopes,
35+
// then we do use the initial position
3536
(previousScope == null ||
36-
compareTargetScopes(direction, currentPosition, previousScope, scope) < 0)
37+
compareTargetScopes(
38+
direction,
39+
requirements.includeDescendantScopes
40+
? initialPosition
41+
: currentPosition,
42+
previousScope,
43+
scope,
44+
) < 0)
3745
);
3846
}
3947

0 commit comments

Comments
 (0)