Skip to main content

Class: RangeSelection

lexical.RangeSelection

This class is being used only for internal use case of migration GridSelection outside of core package. DO NOT USE THIS CLASS DIRECTLY.

Hierarchy

Constructors

constructor

new RangeSelection(anchor, focus, format, style)

Parameters

NameType
anchorPointType
focusPointType
formatnumber
stylestring

Overrides

INTERNAL_PointSelection.constructor

Defined in

lexical/src/LexicalSelection.ts:535

Properties

_cachedNodes

_cachedNodes: null | LexicalNode[]

Inherited from

INTERNAL_PointSelection._cachedNodes

Defined in

lexical/src/LexicalSelection.ts:284


anchor

anchor: PointType

Inherited from

INTERNAL_PointSelection.anchor

Defined in

lexical/src/LexicalSelection.ts:281


dirty

dirty: boolean

Inherited from

INTERNAL_PointSelection.dirty

Defined in

lexical/src/LexicalSelection.ts:283


focus

focus: PointType

Inherited from

INTERNAL_PointSelection.focus

Defined in

lexical/src/LexicalSelection.ts:282


format

format: number

Defined in

lexical/src/LexicalSelection.ts:532


style

style: string

Defined in

lexical/src/LexicalSelection.ts:533

Methods

applyDOMRange

applyDOMRange(range): void

Attempts to map a DOM selection range onto this Lexical Selection, setting the anchor, focus, and type accordingly

Parameters

NameTypeDescription
rangeStaticRangea DOM Selection range conforming to the StaticRange interface.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:725


clone

clone(): RangeSelection

Creates a new RangeSelection, copying over all the property values from this one.

Returns

RangeSelection

a new RangeSelection with the same property values as this one.

Overrides

INTERNAL_PointSelection.clone

Defined in

lexical/src/LexicalSelection.ts:761


deleteCharacter

deleteCharacter(isBackward): void

Performs one logical character deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters

NameTypeDescription
isBackwardbooleanwhether or not the selection is backwards.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1661


deleteLine

deleteLine(isBackward): void

Performs one logical line deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters

NameTypeDescription
isBackwardbooleanwhether or not the selection is backwards.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1781


deleteWord

deleteWord(isBackward): void

Performs one logical word deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters

NameTypeDescription
isBackwardbooleanwhether or not the selection is backwards.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1804


extract

extract(): LexicalNode[]

Extracts the nodes in the Selection, splitting nodes where necessary to get offset-level precision.

Returns

LexicalNode[]

The nodes in the Selection

Overrides

INTERNAL_PointSelection.extract

Defined in

lexical/src/LexicalSelection.ts:1455


formatText

formatText(formatType): void

Applies the provided format to the TextNodes in the Selection, splitting or merging nodes as necessary.

Parameters

NameTypeDescription
formatTypeTextFormatTypethe format type to apply to the nodes in the Selection.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1178


getCachedNodes

getCachedNodes(): null | LexicalNode[]

Returns

null | LexicalNode[]

Inherited from

INTERNAL_PointSelection.getCachedNodes

Defined in

lexical/src/LexicalSelection.ts:294


getCharacterOffsets

getCharacterOffsets(): [number, number]

Returns the character-based offsets of the Selection, accounting for non-text Points by using the children size or text content.

Returns

[number, number]

the character offsets for the Selection

Inherited from

INTERNAL_PointSelection.getCharacterOffsets

Defined in

lexical/src/LexicalSelection.ts:344


getNodes

getNodes(): LexicalNode[]

Gets all the nodes in the Selection. Uses caching to make it generally suitable for use in hot paths.

Returns

LexicalNode[]

an Array containing all the nodes in the Selection

Overrides

INTERNAL_PointSelection.getNodes

Defined in

lexical/src/LexicalSelection.ts:580


getTextContent

getTextContent(): string

Gets the (plain) text content of all the nodes in the selection.

Returns

string

a string representing the text content of all the nodes in the Selection

Overrides

INTERNAL_PointSelection.getTextContent

Defined in

lexical/src/LexicalSelection.ts:657


hasFormat

hasFormat(type): boolean

Returns whether the provided TextFormatType is present on the Selection. This will be true if any node in the Selection has the specified format.

Parameters

NameTypeDescription
typeTextFormatTypethe TextFormatType to check for.

Returns

boolean

true if the provided format is currently toggled on on the Selection, false otherwise.

Defined in

lexical/src/LexicalSelection.ts:800


insertLineBreak

insertLineBreak(selectStart?): void

Inserts a logical linebreak, which may be a new LineBreakNode or a new ParagraphNode, into the EditorState at the current Selection.

Parameters

NameType
selectStart?boolean

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1438


insertNodes

insertNodes(nodes): void

Attempts 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 accomodate the incoming ones.

Parameters

NameTypeDescription
nodesLexicalNode[]the nodes to insert

Returns

void

Overrides

INTERNAL_PointSelection.insertNodes

Defined in

lexical/src/LexicalSelection.ts:1309


insertParagraph

insertParagraph(): null | ElementNode

Inserts a new ParagraphNode into the EditorState at the current Selection

Returns

null | ElementNode

the newly inserted node.

Defined in

lexical/src/LexicalSelection.ts:1410


insertRawText

insertRawText(text): void

Attempts to insert the provided text into the EditorState at the current Selection. converts tabs, newlines, and carriage returns into LexicalNodes.

Parameters

NameTypeDescription
textstringthe text to insert into the Selection

Returns

void

Overrides

INTERNAL_PointSelection.insertRawText

Defined in

lexical/src/LexicalSelection.ts:811


insertText

insertText(text): void

Attempts to insert the provided text into the EditorState at the current Selection as a new Lexical TextNode, according to a series of insertion heuristics based on the selection type and position.

Parameters

NameTypeDescription
textstringthe text to insert into the Selection

Returns

void

Overrides

INTERNAL_PointSelection.insertText

Defined in

lexical/src/LexicalSelection.ts:834


is

is(selection): boolean

Used to check if the provided selections is equal to this one by value, inluding anchor, focus, format, and style properties.

Parameters

NameTypeDescription
selectionnull | BaseSelectionthe Selection to compare this one to.

Returns

boolean

true if the Selections are equal, false otherwise.

Overrides

INTERNAL_PointSelection.is

Defined in

lexical/src/LexicalSelection.ts:552


isBackward

isBackward(): boolean

Returns whether the Selection is "backwards", meaning the focus logically precedes the anchor in the EditorState.

Returns

boolean

true if the Selection is backwards, false otherwise.

Inherited from

INTERNAL_PointSelection.isBackward

Defined in

lexical/src/LexicalSelection.ts:334


isCollapsed

isCollapsed(): boolean

Returns whether the Selection is "collapsed", meaning the anchor and focus are the same node and have the same offset.

Returns

boolean

true if the Selection is collapsed, false otherwise.

Overrides

INTERNAL_PointSelection.isCollapsed

Defined in

lexical/src/LexicalSelection.ts:570


modify

modify(alter, isBackward, granularity): void

Modifies 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.

Parameters

NameTypeDescription
alter"move" | "extend"the type of modification to perform
isBackwardbooleanwhether or not selection is backwards
granularity"character" | "word" | "lineboundary"the granularity at which to apply the modification

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1513


removeText

removeText(): void

Removes the text in the Selection, adjusting the EditorState accordingly.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:1168


setCachedNodes

setCachedNodes(nodes): void

Parameters

NameType
nodesnull | LexicalNode[]

Returns

void

Inherited from

INTERNAL_PointSelection.setCachedNodes

Defined in

lexical/src/LexicalSelection.ts:298


setStyle

setStyle(style): void

Sets the value of the style property on the Selection

Parameters

NameTypeDescription
stylestringthe style to set at the value of the style property.

Returns

void

Defined in

lexical/src/LexicalSelection.ts:788


setTextNodeRange

setTextNodeRange(anchorNode, anchorOffset, focusNode, focusOffset): void

Sets this Selection to be of type "text" at the provided anchor and focus values.

Parameters

NameTypeDescription
anchorNodeTextNodethe anchor node to set on the Selection
anchorOffsetnumberthe offset to set on the Selection
focusNodeTextNodethe focus node to set on the Selection
focusOffsetnumberthe focus offset to set on the Selection

Returns

void

Defined in

lexical/src/LexicalSelection.ts:640


toggleFormat

toggleFormat(format): void

Toggles the provided format on all the TextNodes in the Selection.

Parameters

NameTypeDescription
formatTextFormatTypea string TextFormatType to toggle on the TextNodes in the selection

Returns

void

Defined in

lexical/src/LexicalSelection.ts:778