Skip to main content

getComposedStaticRange

function

Resolves a DOM Selection's range through any DOM ShadowRoots enclosing `rootElement`, using the standard Selection.getComposedRanges (https://developer.mozilla.org/docs/Web/API/Selection/getComposedRanges) platform API. When a selection is inside a shadow tree the browser retargets `Selection.getRangeAt`/`anchorNode`/`focusNode` to the shadow host, which hides the real nodes Lexical needs to resolve. Passing the enclosing shadow roots to `getComposedRanges` returns the un-retargeted boundary points as a StaticRange (https://developer.mozilla.org/docs/Web/API/StaticRange) (in tree order, i.e. start before end).

function getComposedStaticRange(domSelection: Selection, rootElement: HTMLElement | null): StaticRange | null

Import

import { getComposedStaticRange } from '@modular/sdk/editor';

Notes

returns
The composed StaticRange, or `null` when `rootElement` is in the light DOM, the platform does not implement `getComposedRanges`, or there is no selection.