RangeSelection
classImport
import { RangeSelection } from '@modular/sdk/editor';Members34
- _cachedNodes
LexicalNode[] | null- anchor
PointType- dirty
boolean- focus
PointType- format
number- style
string- applyDOMRange()
(range: StaticRange) => voidAttempts to map a DOM selection range onto this Lexical Selection, setting the anchor, focus, and type accordingly
- clone()
() => RangeSelectionCreates a new RangeSelection, copying over all the property values from this one.
- deleteCharacter()
(isBackward: boolean) => voidPerforms one logical character deletion operation on the EditorState based on the current Selection. Handles different node types.
- deleteLine()
(isBackward: boolean) => voidPerforms one logical line deletion operation on the EditorState based on the current Selection. Handles different node types.
- deleteWord()
(isBackward: boolean) => voidPerforms one logical word deletion operation on the EditorState based on the current Selection. Handles different node types.
- extract()
() => LexicalNode[]Extracts the nodes in the Selection, splitting nodes where necessary to get offset-level precision.
- formatText()
(formatType: TextFormatType, alignWithFormat?: number | null) => voidApplies the provided format to the TextNodes in the Selection, splitting or merging nodes as necessary.
- forwardDeletion()
(anchor: PointType, anchorNode: TextNode | ElementNode, isBackward: boolean) => booleanHelper for handling forward character and word deletion that prevents element nodes like a table, columns layout being destroyed
- getCachedNodes()
() => LexicalNode[] | null- getNodes()
() => LexicalNode[]Gets all the nodes in the Selection. Uses caching to make it generally suitable for use in hot paths. See also the CaretRange APIs (starting with $caretRangeFromSelection), which are likely to provide a better foundation for any operation where partial selection is relevant (e.g. the anchor or focus are inside an ElementNode and TextNode)
- getStartEndPoints()
() => [PointType, PointType]- getTextContent()
() => stringGets the (plain) text content of all the nodes in the selection.
- hasFormat()
(type: TextFormatType) => booleanReturns whether the provided TextFormatType is present on the Selection. This will be true if all text nodes in the Selection have the specified format.
- insertLineBreak()
(selectStart?: boolean) => voidInserts a logical linebreak, which may be a new LineBreakNode or a new ParagraphNode, into the EditorState at the current Selection.
- insertNodes()
(nodes: LexicalNode[]) => voidAttempts to "intelligently" insert an arbitrary list of Lexical nodes into the EditorState at the current Selection according to a set of heuristics that determine how surrounding nodes should be changed, replaced, or moved to accommodate the incoming ones.
- insertParagraph()
() => ElementNode | nullInserts a new ParagraphNode into the EditorState at the current Selection
- insertRawText()
(text: string) => voidAttempts to insert the provided text into the EditorState at the current Selection. converts tabs, newlines, and carriage returns into LexicalNodes.
- insertText()
(text: string) => voidInsert the provided text into the EditorState at the current Selection.
- is()
(selection: null | BaseSelection) => booleanUsed to check if the provided selections is equal to this one by value, including anchor, focus, format, and style properties.
- isBackward()
() => booleanReturns whether the Selection is "backwards", meaning the focus logically precedes the anchor in the EditorState.
- isCollapsed()
() => booleanReturns whether the Selection is "collapsed", meaning the anchor and focus are the same node and have the same offset.
- modify()
(alter: 'move' | 'extend', isBackward: boolean, granularity: 'character' | 'word' | 'lineboundary') => voidModifies the Selection according to the parameters and a set of heuristics that account for various node types. Can be used to safely move or extend selection by one logical "unit" without dealing explicitly with all the possible node types.
- removeText()
() => voidRemoves the text in the Selection, adjusting the EditorState accordingly.
- setCachedNodes()
(nodes: LexicalNode[] | null) => void- setFormat()
(format: number) => voidSets the value of the format property on the Selection
- setStyle()
(style: string) => voidSets the value of the style property on the Selection
- setTextNodeRange()
(anchorNode: TextNode, anchorOffset: number, focusNode: TextNode, focusOffset: number) => thisSets this Selection to be of type "text" at the provided anchor and focus values.
- toggleFormat()
(format: TextFormatType) => voidToggles the provided format on all the TextNodes in the Selection.