Skip to content

Add includeDescendantScopes field to scope handlers #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const DEFAULT_REQUIREMENTS: Omit<ScopeIteratorRequirements, "distalPosition"> =
containment: null,
allowAdjacentScopes: false,
skipAncestorScopes: false,
includeDescendantScopes: false,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,17 @@ export interface ScopeIteratorRequirements {
* @default false
*/
skipAncestorScopes: boolean;

/**
* Indicates whether the ScopeHandler should yield a scope if it is a
* descendant of any scope that has been previously yielded.
*
* - `true` means that descendant scopes of any previously yielded scope will
* be yielded.
* - `false` means that descendant scopes of any previously yielded scope will
* not be yielded.
*
* @default false
*/
includeDescendantScopes: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ export function shouldYieldScope(
checkRequirements(initialPosition, requirements, previousScope, scope) &&
// Note that we're using `currentPosition` instead of `initialPosition`
// below, because we want to filter out scopes that are strictly contained
// by previous scopes.
// by previous scopes. However, if we want to include descendant scopes,
// then we do use the initial position
(previousScope == null ||
compareTargetScopes(direction, currentPosition, previousScope, scope) < 0)
compareTargetScopes(
direction,
requirements.includeDescendantScopes
? initialPosition
: currentPosition,
previousScope,
scope,
) < 0)
);
}

Expand Down