Skip to main content

Interface: ScopeHandler

processTargets/modifiers/scopeHandlers/scopeHandler.types.ScopeHandler

Represents a scope type. The functions in this interface allow us to find specific instances of the given scope type in a document. These functions are used by the various modifier stages to implement modifiers that involve the given scope type, such as containing, every, next, etc.

Note that some scope types are hierarchical, ie one scope of the given type can contain another scope of the same type. For example, a function can contain other functions, so functions are hierarchical. Surrounding pairs are also hierarchical, as they can be nested. Many scope types are not hierarchical, though, eg line, token, word, etc.

Note also that scope's domains are never allowed to partially overlap. Scopes can be directly adjacent to one another, or have one or more characters between them, or, for hierarchical scopes, one scope can completely contain another scope.

Note that there are helpers that can sometimes be used to avoid implementing a scope handler from scratch, eg NestedScopeHandler.

Implemented by

Properties

iterationScopeType

Readonly 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).

Defined in

processTargets/modifiers/scopeHandlers/scopeHandler.types.ts:39


scopeType

Readonly scopeType: ScopeType

The scope type handled by this scope handler

Defined in

processTargets/modifiers/scopeHandlers/scopeHandler.types.ts:32

Methods

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

NameTypeDescription
editorTextEditorThe editor containing position
positionPositionThe position from which to start
directionDirectionThe direction to go relative to position
requirements?Partial<ScopeIteratorRequirements>Extra requirements of the scopes being returned

Returns

Iterable<TargetScope>

An iterable of scopes

Defined in

processTargets/modifiers/scopeHandlers/scopeHandler.types.ts:53


isPreferredOver

Optional isPreferredOver(scopeA, scopeB): undefined | boolean

This optional function can be defined to indicate a preference when the containing scope modifier is applied to an empty target that is directly in between two instances of scope. By default we prefer the right scope, but if you define this function you can indicate another way to break these ties.

Parameters

NameTypeDescription
scopeATargetScopeA scope
scopeBTargetScopeAnother scope

Returns

undefined | boolean

A boolean indicating if {@link scopeA} is preferred over {@link scopeB}. A value of undefined indicates no preference.

Defined in

processTargets/modifiers/scopeHandlers/scopeHandler.types.ts:71