Class: BaseScopeHandler
processTargets/modifiers/scopeHandlers/BaseScopeHandler.BaseScopeHandler
All scope handlers should derive from this base class
Hierarchy
BaseScopeHandler
Implements
Constructors
constructor
• new BaseScopeHandler()
Properties
isHierarchical
• Protected
Readonly
Abstract
isHierarchical: boolean
Indicates whether scopes are allowed to contain one another. If false
, we
can optimise the algorithm by making certain assumptions.
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:30
iterationScopeType
• Readonly
Abstract
iterationScopeType: ScopeType
The scope type of the default iteration scope of this scope type. This
scope type will be used when the input target has no explicit range (ie
Target.hasExplicitRange is false
).
Implementation of
ScopeHandler.iterationScopeType
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:24
scopeType
• Readonly
Abstract
scopeType: ScopeType
The scope type handled by this scope handler
Implementation of
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:23
Methods
canStopEarly
▸ Private
canStopEarly(position
, direction
, requirements
, __namedParameters
): boolean
Parameters
Name | Type |
---|---|
position | Position |
direction | Direction |
requirements | ScopeIteratorRequirements |
__namedParameters | TargetScope |
Returns
boolean
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:128
generateScopeCandidates
▸ Protected
Abstract
generateScopeCandidates(editor
, position
, direction
, hints
): Iterable
<TargetScope
>
Returns an iterable that yields scopes.
If your scope type is not hierarchical, and {@link direction} is
"forward"
, yield all scopes whose domain's
end is equal to or after position in document
order.
If your scope type is not hierarchical, and {@link direction} is
"backward"
, yield all scopes whose domain's
start is equal to or before position, in
reverse document order.
If your scope type is hierarchical, and {@link direction} is "forward"
,
walk forward starting at position (including position). Any time a
scope's domain ends or starts, yield that scope.
If multiple domains start or end at a particular point, break ties as
follows:
- First yield any scopes with empty domain.
- Then yield any scopes whose domains are ending, in reverse order of where they start.
- Then yield the scope with minimal domain that is starting. Any time you yield a scope, advance your position to the end of the scope, but when considering this new position, don't return this scope again.
If your scope type is hierarchical, and {@link direction} is
"backward"
, walk backward starting at position (including
position). Any time a scope's domain ends or
starts, yield that scope. If multiple domains start or end at a particular
point, break ties as follows:
- First yield any scopes with empty domain.
- Then yield any scopes whose domains are starting, in order of where they end.
- Then yield the scope with minimal domain that is ending. Any time you yield a scope, advance your position to the start of the scope, but when considering this new position, don't return this scope again.
Note that the {@link hints} argument can be ignored, but you are welcome to use it to improve performance. For example, knowing the ScopeIteratorRequirements.distalPosition can be useful if you need to query a list of scopes in bulk.
Some notes:
- Once you have yielded a scope, you do not need to yield any scopes contained by that scope.
- You can yield the same scope more than once if it makes your life easier
The only strict requirements are that
- you yield every scope that might meet the requirements
- you yield scopes in the correct order
Parameters
Name | Type | Description |
---|---|---|
editor | TextEditor | The editor containing position |
position | Position | The position from which to start |
direction | Direction | The direction to go relative to position |
hints | ScopeIteratorRequirements | Optional hints about which scopes should be returned |
Returns
Iterable
<TargetScope
>
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:92
generateScopes
▸ generateScopes(editor
, position
, direction
, requirements?
): Iterable
<TargetScope
>
Returns an iterable of scopes meeting the requirements in {@link requirements}, yielded in a specific order. See generateScopeCandidates and compareTargetScopes for more on the order.
Parameters
Name | Type |
---|---|
editor | TextEditor |
position | Position |
direction | Direction |
requirements | Partial <ScopeIteratorRequirements > |
Returns
Iterable
<TargetScope
>
Implementation of
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:99