Class: RangeSelection
lexical.RangeSelection
Implements
Constructors
constructor
• new RangeSelection(anchor
, focus
, format
, style
): RangeSelection
Parameters
Name | Type |
---|---|
anchor | PointType |
focus | PointType |
format | number |
style | string |
Returns
Defined in
packages/lexical/src/LexicalSelection.ts:406
Properties
_cachedNodes
• _cachedNodes: null
| LexicalNode
[]
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:403
anchor
• anchor: PointType
Defined in
packages/lexical/src/LexicalSelection.ts:401
dirty
• dirty: boolean
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:404
focus
• focus: PointType
Defined in
packages/lexical/src/LexicalSelection.ts:402
format
• format: number
Defined in
packages/lexical/src/LexicalSelection.ts:399
style
• style: string
Defined in
packages/lexical/src/LexicalSelection.ts:400
Methods
applyDOMRange
▸ applyDOMRange(range
): void
Attempts to map a DOM selection range onto this Lexical Selection, setting the anchor, focus, and type accordingly
Parameters
Name | Type | Description |
---|---|---|
range | StaticRange | a DOM Selection range conforming to the StaticRange interface. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:609
clone
▸ clone(): RangeSelection
Creates a new RangeSelection, copying over all the property values from this one.
Returns
a new RangeSelection with the same property values as this one.
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:645
deleteCharacter
▸ deleteCharacter(isBackward
): void
Performs one logical character deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
Name | Type | Description |
---|---|---|
isBackward | boolean | whether or not the selection is backwards. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1742
deleteLine
▸ deleteLine(isBackward
): void
Performs one logical line deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
Name | Type | Description |
---|---|---|
isBackward | boolean | whether or not the selection is backwards. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1848
deleteWord
▸ deleteWord(isBackward
): void
Performs one logical word deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
Name | Type | Description |
---|---|---|
isBackward | boolean | whether or not the selection is backwards. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1883
extract
▸ extract(): LexicalNode
[]
Extracts the nodes in the Selection, splitting nodes where necessary to get offset-level precision.
Returns
The nodes in the Selection
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:1503
formatText
▸ formatText(formatType
, alignWithFormat?
): void
Applies the provided format to the TextNodes in the Selection, splitting or merging nodes as necessary.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
formatType | TextFormatType | undefined | the format type to apply to the nodes in the Selection. |
alignWithFormat | null | number | null | a 32-bit integer representing formatting flags to align with. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1191
forwardDeletion
▸ forwardDeletion(anchor
, anchorNode
, isBackward
): boolean
Helper for handling forward character and word deletion that prevents element nodes like a table, columns layout being destroyed
Parameters
Name | Type | Description |
---|---|---|
anchor | PointType | the anchor |
anchorNode | ElementNode | TextNode | the anchor node in the selection |
isBackward | boolean | whether or not selection is backwards |
Returns
boolean
Defined in
packages/lexical/src/LexicalSelection.ts:1710
getCachedNodes
▸ getCachedNodes(): null
| LexicalNode
[]
Returns
null
| LexicalNode
[]
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:422
getNodes
▸ getNodes(): LexicalNode
[]
Gets all the nodes in the Selection. Uses caching to make it generally suitable for use in hot paths.
Returns
an Array containing all the nodes in the Selection
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:464
getStartEndPoints
▸ getStartEndPoints(): null
| [PointType
, PointType
]
Returns
Implementation of
BaseSelection.getStartEndPoints
Defined in
packages/lexical/src/LexicalSelection.ts:1904
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
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:541
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
Name | Type | Description |
---|---|---|
type | TextFormatType | the TextFormatType to check for. |
Returns
boolean
true if the provided format is currently toggled on on the Selection, false otherwise.
Defined in
packages/lexical/src/LexicalSelection.ts:684
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
Name | Type |
---|---|
selectStart? | boolean |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1486
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 accommodate the incoming ones.
Parameters
Name | Type | Description |
---|---|---|
nodes | LexicalNode [] | the nodes to insert |
Returns
void
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:1342
insertParagraph
▸ insertParagraph(): null
| ElementNode
Inserts a new ParagraphNode into the EditorState at the current Selection
Returns
null
| ElementNode
the newly inserted node.
Defined in
packages/lexical/src/LexicalSelection.ts:1455
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
Name | Type | Description |
---|---|---|
text | string | the text to insert into the Selection |
Returns
void
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:695
insertText
▸ insertText(text
): void
Insert the provided text into the EditorState at the current Selection.
Parameters
Name | Type | Description |
---|---|---|
text | string | the text to insert into the Selection |
Returns
void
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:717
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
Name | Type | Description |
---|---|---|
selection | null | BaseSelection | the Selection to compare this one to. |
Returns
boolean
true if the Selections are equal, false otherwise.
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:436
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.
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:1900
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.
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:454
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
Name | Type | Description |
---|---|---|
alter | "move" | "extend" | the type of modification to perform |
isBackward | boolean | whether or not selection is backwards |
granularity | "character" | "word" | "lineboundary" | the granularity at which to apply the modification |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1561
removeText
▸ removeText(): void
Removes the text in the Selection, adjusting the EditorState accordingly.
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:1108
setCachedNodes
▸ setCachedNodes(nodes
): void
Parameters
Name | Type |
---|---|
nodes | null | LexicalNode [] |
Returns
void
Implementation of
Defined in
packages/lexical/src/LexicalSelection.ts:426
setStyle
▸ setStyle(style
): void
Sets the value of the style property on the Selection
Parameters
Name | Type | Description |
---|---|---|
style | string | the style to set at the value of the style property. |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:672
setTextNodeRange
▸ setTextNodeRange(anchorNode
, anchorOffset
, focusNode
, focusOffset
): void
Sets this Selection to be of type "text" at the provided anchor and focus values.
Parameters
Name | Type | Description |
---|---|---|
anchorNode | TextNode | the anchor node to set on the Selection |
anchorOffset | number | the offset to set on the Selection |
focusNode | TextNode | the focus node to set on the Selection |
focusOffset | number | the focus offset to set on the Selection |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:524
toggleFormat
▸ toggleFormat(format
): void
Toggles the provided format on all the TextNodes in the Selection.
Parameters
Name | Type | Description |
---|---|---|
format | TextFormatType | a string TextFormatType to toggle on the TextNodes in the selection |
Returns
void