Skip to main content

Class: BaseScopeHandler

processTargets/modifiers/scopeHandlers/BaseScopeHandler.BaseScopeHandler

All scope handlers should derive from this base class

Hierarchy

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:25


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:19


scopeType

Readonly Abstract scopeType: ScopeType

The scope type handled by this scope handler

Implementation of

ScopeHandler.scopeType

Defined in

processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:18

Methods

canStopEarly

Private canStopEarly(position, direction, requirements, __namedParameters): boolean

Parameters

NameType
positionPosition
directionDirection
requirementsScopeIteratorRequirements
__namedParametersTargetScope

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:

  1. First yield any scopes with empty domain.
  2. Then yield any scopes whose domains are ending, in reverse order of where they start.
  3. 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:

  1. First yield any scopes with empty domain.
  2. Then yield any scopes whose domains are starting, in order of where they end.
  3. 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

NameTypeDescription
editorTextEditorThe editor containing position
positionPositionThe position from which to start
directionDirectionThe direction to go relative to position
hints?ScopeIteratorRequirementsOptional hints about which scopes should be returned

Returns

Iterable<TargetScope>

Defined in

processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:87


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

NameType
editorTextEditor
positionPosition
directionDirection
requirementsundefined | ScopeIteratorRequirements

Returns

Iterable<TargetScope>

Implementation of

ScopeHandler.generateScopes

Defined in

processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:94