Interface: TextSliceCaret<T, D>
lexical.TextSliceCaret
A TextSliceCaret is a special case of a BreadthNodeCaret that also carries an index pair used for representing partially selected TextNode at the edges of a NodeCaretRange
Type parameters
| Name | Type |
|---|---|
T | extends TextNode = TextNode |
D | extends CaretDirection = CaretDirection |
Hierarchy
-
BreadthNodeCaret<T,D>↳
TextSliceCaret
Properties
direction
• Readonly direction: D
next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:39
getAdjacentCaret
• getAdjacentCaret: () => null | BreadthNodeCaret<LexicalNode, D>
Get a new BreadthNodeCaret from getNodeAtCaret() in the same direction. This is used for traversals, but only goes in the breadth (sibling) direction.
Type declaration
▸ (): null | BreadthNodeCaret<LexicalNode, D>
Returns
null | BreadthNodeCaret<LexicalNode, D>
Inherited from
BreadthNodeCaret.getAdjacentCaret
Defined in
packages/lexical/src/LexicalCaret.ts:61
getChildCaret
• getChildCaret: () => null | DepthNodeCaret<T & ElementNode, D>
If the origin of this node is an ElementNode, return the DepthNodeCaret of this origin in the same direction. If the origin is not an ElementNode, this will return null.
Type declaration
▸ (): null | DepthNodeCaret<T & ElementNode, D>
Returns
null | DepthNodeCaret<T & ElementNode, D>
Inherited from
BreadthNodeCaret.getChildCaret
Defined in
packages/lexical/src/LexicalCaret.ts:159
getFlipped
• getFlipped: () => NodeCaret<FlipDirection<D>>
Get a new NodeCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For example, given a non-empty parent with a firstChild and lastChild, and a second emptyParent node with no children:
Example
caret.getFlipped().getFlipped().is(caret) === true;
$getDepthCaret(parent, 'next').getFlipped().is($getBreadthCaret(firstChild, 'previous')) === true;
$getBreadthCaret(lastChild, 'next').getFlipped().is($getDepthCaret(parent, 'previous')) === true;
$getBreadthCaret(firstChild, 'next).getFlipped().is($getBreadthCaret(lastChild, 'previous')) === true;
$getDepthCaret(emptyParent, 'next').getFlipped().is($getDepthCaret(emptyParent, 'previous')) === true;
Type declaration
▸ (): NodeCaret<FlipDirection<D>>
Returns
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:55
getNodeAtCaret
• getNodeAtCaret: () => null | LexicalNode
Get the node connected to the origin in the caret's direction, or null if there is no node
Type declaration
▸ (): null | LexicalNode
Returns
null | LexicalNode
Inherited from
BreadthNodeCaret.getNodeAtCaret
Defined in
packages/lexical/src/LexicalCaret.ts:59
getParentAtCaret
• getParentAtCaret: () => ElementNode
Get the ElementNode that is the logical parent (origin for DepthNodeCaret, origin.getParentOrThrow() for BreadthNodeCaret)
Type declaration
▸ (): ElementNode
Returns
Inherited from
BreadthNodeCaret.getParentAtCaret
Defined in
packages/lexical/src/LexicalCaret.ts:57
getParentCaret
• getParentCaret: (mode: RootMode) => null | BreadthNodeCaret<ElementNode, D>
Get the caret in the same direction from the parent of this origin.
Type declaration
▸ (mode): null | BreadthNodeCaret<ElementNode, D>
Parameters
| Name | Type | Description |
|---|---|---|
mode | RootMode | 'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root |
Returns
null | BreadthNodeCaret<ElementNode, D>
Inherited from
BreadthNodeCaret.getParentCaret
Defined in
packages/lexical/src/LexicalCaret.ts:166
indexEnd
• Readonly indexEnd: number
Defined in
packages/lexical/src/LexicalCaret.ts:191
indexStart
• Readonly indexStart: number
Defined in
packages/lexical/src/LexicalCaret.ts:190
insert
• insert: (node: LexicalNode) => this
Insert a node connected to origin in this direction.
For a BreadthNodeCaret this is origin.insertAfter(node) for next, or origin.insertBefore(node) for previous.
For a DepthNodeCaret this is origin.splice(0, 0, [node]) for next or origin.append(node) for previous.
Type declaration
▸ (node): this
Parameters
| Name | Type |
|---|---|
node | LexicalNode |
Returns
this
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:69
is
• is: (other: null | NodeCaret<CaretDirection>) => boolean
Retun true if other is a caret with the same origin (by node key comparion), type, and direction
Type declaration
▸ (other): boolean
Parameters
| Name | Type |
|---|---|
other | null | NodeCaret<CaretDirection> |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:41
origin
• Readonly origin: T
The origin node of this caret, typically this is what you will use in traversals
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:35
remove
• remove: () => this
Remove the getNodeAtCaret() node, if it exists
Type declaration
▸ (): this
Returns
this
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:63
replaceOrInsert
• replaceOrInsert: (node: LexicalNode, includeChildren?: boolean) => this
If getNodeAtCaret() is null then replace it with node, otherwise insert node
Type declaration
▸ (node, includeChildren?): this
Parameters
| Name | Type |
|---|---|
node | LexicalNode |
includeChildren? | boolean |
Returns
this
Inherited from
BreadthNodeCaret.replaceOrInsert
Defined in
packages/lexical/src/LexicalCaret.ts:71
splice
• splice: (deleteCount: number, nodes: Iterable<LexicalNode>, nodesDirection?: CaretDirection) => this
Splice an iterable (typically an Array) of nodes into this location.
Type declaration
▸ (deleteCount, nodes, nodesDirection?): this
Parameters
| Name | Type | Description |
|---|---|---|
deleteCount | number | The number of existing nodes to replace or delete |
nodes | Iterable<LexicalNode> | An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes |
nodesDirection? | CaretDirection | The direction of the nodes iterable, defaults to 'next' |
Returns
this
Inherited from
Defined in
packages/lexical/src/LexicalCaret.ts:79
type
• Readonly type: "breadth"
breadth for a BreadthNodeCaret (pointing at the next or previous sibling) or depth for a DepthNodeCaret (pointing at the first or last child)