Interface: TextPointCaret<T, D>
lexical.TextPointCaret
A TextPointCaret is a special case of a SiblingCaret that also carries an offset used for representing partially selected TextNode at the edges of a CaretRange.
The direction determines which part of the text is adjacent to the caret, if next it's all of the text after offset. If previous, it's all of the text before offset.
While this can be used in place of any SiblingCaret of a TextNode, the offset into the text will be ignored except in contexts that specifically use the TextPointCaret or PointCaret types.
Type parameters
Name | Type |
---|---|
T | extends TextNode = TextNode |
D | extends CaretDirection = CaretDirection |
Hierarchy
-
BaseCaret
<T
,D
,"text"
>↳
TextPointCaret
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/caret/LexicalCaret.ts:55
getAdjacentCaret
• getAdjacentCaret: () => null
| SiblingCaret
<LexicalNode
, D
>
Get a new SiblingCaret from getNodeAtCaret() in the same direction.
Type declaration
▸ (): null
| SiblingCaret
<LexicalNode
, D
>
Returns
null
| SiblingCaret
<LexicalNode
, D
>
Inherited from
Defined in
packages/lexical/src/caret/LexicalCaret.ts:61
getChildCaret
• getChildCaret: () => null
A TextPointCaret can not have a ChildCaret.
Type declaration
▸ (): null
Returns
null
Defined in
packages/lexical/src/caret/LexicalCaret.ts:289
getFlipped
• getFlipped: () => TextPointCaret
<T
, FlipDirection
<D
>>
Get a new TextPointCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For a TextPointCaret this merely flips the direction because the arrow is internal to the node.
Example
caret.getFlipped().getFlipped().is(caret) === true;
Type declaration
▸ (): TextPointCaret
<T
, FlipDirection
<D
>>
Returns
TextPointCaret
<T
, FlipDirection
<D
>>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:320
getLatest
• getLatest: () => TextPointCaret
<T
, D
>
Get a new caret with the latest origin pointer
Type declaration
▸ (): TextPointCaret
<T
, D
>
Returns
TextPointCaret
<T
, D
>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:285
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
Defined in
packages/lexical/src/caret/LexicalCaret.ts:59
getParentAtCaret
• getParentAtCaret: () => null
| ElementNode
Get the ElementNode that is the logical parent (origin
for ChildCaret
, origin.getParent()
for SiblingCaret
)
Type declaration
▸ (): null
| ElementNode
Returns
null
| ElementNode
Inherited from
Defined in
packages/lexical/src/caret/LexicalCaret.ts:57
getParentCaret
• getParentCaret: (mode?
: RootMode
) => null
| SiblingCaret
<ElementNode
, D
>
Get the caret in the same direction from the parent of this origin.
Type declaration
▸ (mode?
): null
| SiblingCaret
<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
| SiblingCaret
<ElementNode
, D
>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:296
getSiblingCaret
• getSiblingCaret: () => SiblingCaret
<T
, D
>
Get a new SiblingCaret with this same node
Type declaration
▸ (): SiblingCaret
<T
, D
>
Returns
SiblingCaret
<T
, D
>
Inherited from
Defined in
packages/lexical/src/caret/LexicalCaret.ts:65
insert
• insert: (node
: LexicalNode
) => this
Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed).
For a SiblingCaret
this is origin.insertAfter(node)
for next, or origin.insertBefore(node)
for previous.
For a ChildCaret
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/caret/LexicalCaret.ts:73
isSameNodeCaret
• isSameNodeCaret: (other
: undefined
| null
| PointCaret
<CaretDirection
>) => other is TextPointCaret<T, D> | SiblingCaret<T, D>
Retun true if other is a TextPointCaret or SiblingCaret with the same origin (by node key comparion) and direction.
Type declaration
▸ (other
): other is TextPointCaret<T, D> | SiblingCaret<T, D>
Parameters
Name | Type |
---|---|
other | undefined | null | PointCaret <CaretDirection > |
Returns
other is TextPointCaret<T, D> | SiblingCaret<T, D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:301
isSamePointCaret
• isSamePointCaret: (other
: undefined
| null
| PointCaret
<CaretDirection
>) => other is TextPointCaret<T, D>
Retun true if other is a ChildCaret with the same origin (by node key comparion) and direction.
Type declaration
▸ (other
): other is TextPointCaret<T, D>
Parameters
Name | Type |
---|---|
other | undefined | null | PointCaret <CaretDirection > |
Returns
other is TextPointCaret<T, D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:308
offset
• Readonly
offset: number
The offset into the string
Defined in
packages/lexical/src/caret/LexicalCaret.ts:283
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/caret/LexicalCaret.ts:51
remove
• remove: () => this
Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists
Type declaration
▸ (): this
Returns
this
Inherited from
Defined in
packages/lexical/src/caret/LexicalCaret.ts:67
replaceOrInsert
• replaceOrInsert: (node
: LexicalNode
, includeChildren?
: boolean
) => this
If getNodeAtCaret() is not 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
Defined in
packages/lexical/src/caret/LexicalCaret.ts:75
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/caret/LexicalCaret.ts:83
type
• Readonly
type: "text"
sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)