Sign up (with export icon)

ShadowSelection

Api-class iconclass

A Selection view over the composed ranges of a set of shadow roots. Read accessors are resolved live from the composed ranges on each access, so the view stays in sync with the underlying document selection; selection mutations are delegated to it. Only the subset of the Selection interface consumed by the editor is implemented, so getSelection() returns it alongside the native Selection.

Properties

Static properties

  • Chevron-right icon

    _useLegacyComposedRanges: boolean
    Lock iconprivatestatic

    Whether the engine only accepts the legacy rest-parameter form of getComposedRanges(). This is a fixed property of the engine, so it is detected once (the first call throws on the dictionary form) and cached for all instances, keeping the exception off the selection-read hot path.

Methods

  • Chevron-right icon

    constructor( domSelection, shadowRoots )
    internal

    Parameters

    domSelection: Selection
    shadowRoots: Array<ShadowRoot>
  • Chevron-right icon

    addRange( range ) → void

    Parameters

    range: Range

    Returns

    void
  • Chevron-right icon

    collapse( node, offset? ) → void

    Parameters

    node: Node | null
    offset?: number

    Returns

    void
  • Chevron-right icon

    extend( node, offset? ) → void

    Parameters

    node: Node
    offset?: number

    Returns

    void
  • Chevron-right icon

    getRangeAt( index ) → Range

    Parameters

    index: number

    Returns

    Range
  • Chevron-right icon

    removeAllRanges() → void

  • Chevron-right icon

    setBaseAndExtent( anchorNode, anchorOffset, focusNode, focusOffset ) → void

    Parameters

    anchorNode: Node
    anchorOffset: number
    focusNode: Node
    focusOffset: number

    Returns

    void
  • Chevron-right icon

    _getComposedRanges() → Array<StaticRange>
    Lock iconprivate

    The raw composed ranges reported for the shadow roots by the underlying selection.

    Returns

    Array<StaticRange>
  • Chevron-right icon

    _getDirection( rootNode ) → string
    Lock iconprivate

    The direction of the underlying selection, preferring the one reported by Blink's shadow-scoped selection, which stays meaningful for a mouse selection made inside a shadow root.

    Parameters

    rootNode: Node

    Returns

    string
  • Chevron-right icon

    _getEndpoint( endpoint ) → object
    Lock iconprivate

    The anchor or focus endpoint of the first composed range.

    getComposedRanges() returns ranges in document order (start before end); the anchor/focus orientation therefore has to come from Selection#direction. Known limitation: WebKit and Blink report direction as 'none' for a selection made with the mouse inside a shadow root (a keyboard selection reports it correctly). Blink's shadow-scoped selection still knows the direction in that case, so it is consulted first; it is of no use for the ranges themselves, as it covers a single tree only. Safari has no such API, so its mouse selections fall back to forward.

    Parameters

    endpoint: 'anchor' | 'focus'

    Returns

    object
  • Chevron-right icon

    _getRanges() → Array<StaticRange>
    Lock iconprivate

    The composed ranges fully contained in one of the trees on the path from the given nodes to the document, in document order (start before end).

    Only ranges whose both endpoints resolve into the same tree can be represented as a live, single-tree Range. A range crossing a shadow boundary is therefore dropped, and so is one resolving into an unrelated tree, rather than surfacing foreign nodes. The document itself is one of those trees: it is where every node ends up when walking out of its shadow roots, and it is where a selection made in a sibling light-DOM editable lives, so such a selection is kept rather than dropped.

    A range with an endpoint outside its container is dropped as well, see isOffsetInNode() below.

    Returns

    Array<StaticRange>