Skip to main content

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

NameType
Textends TextNode = TextNode
Dextends CaretDirection = CaretDirection

Hierarchy

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

SiblingCaret.direction

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

SiblingCaret.getAdjacentCaret

Defined in

packages/lexical/src/caret/LexicalCaret.ts:82


getChildCaret

getChildCaret: () => null | ChildCaret<T & ElementNode, D>

If the origin of this node is an ElementNode, return the ChildCaret of this origin in the same direction. If the origin is not an ElementNode, this will return null.

Type declaration

▸ (): null | ChildCaret<T & ElementNode, D>

Returns

null | ChildCaret<T & ElementNode, D>

Inherited from

SiblingCaret.getChildCaret

Defined in

packages/lexical/src/caret/LexicalCaret.ts:192


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;
$getChildCaret(parent, 'next').getFlipped().is($getSiblingCaret(firstChild, 'previous')) === true;
$getSiblingCaret(lastChild, 'next').getFlipped().is($getChildCaret(parent, 'previous')) === true;
$getSiblingCaret(firstChild, 'next).getFlipped().is($getSiblingCaret(lastChild, 'previous')) === true;
$getChildCaret(emptyParent, 'next').getFlipped().is($getChildCaret(emptyParent, 'previous')) === true;

Type declaration

▸ (): NodeCaret<FlipDirection<D>>

Returns

NodeCaret<FlipDirection<D>>

Inherited from

SiblingCaret.getFlipped

Defined in

packages/lexical/src/caret/LexicalCaret.ts:76


getLatest

getLatest: () => TextPointCaret<T, D>

Get a new caret with the latest origin pointer

Type declaration

▸ (): TextPointCaret<T, D>

Returns

TextPointCaret<T, D>

Overrides

SiblingCaret.getLatest

Defined in

packages/lexical/src/caret/LexicalCaret.ts:235


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

SiblingCaret.getNodeAtCaret

Defined in

packages/lexical/src/caret/LexicalCaret.ts:80


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

SiblingCaret.getParentAtCaret

Defined in

packages/lexical/src/caret/LexicalCaret.ts:78


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
NameTypeDescription
modeRootMode'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root
Returns

null | SiblingCaret<ElementNode, D>

Inherited from

SiblingCaret.getParentCaret

Defined in

packages/lexical/src/caret/LexicalCaret.ts:199


insert

insert: (node: LexicalNode) => this

Insert a node connected to origin in this direction. 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
NameType
nodeLexicalNode
Returns

this

Inherited from

SiblingCaret.insert

Defined in

packages/lexical/src/caret/LexicalCaret.ts:90


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.

Note that this will not check the offset of a TextPointCaret because it is otherwise indistinguishable from a SiblingCaret. Use $isSameTextPointCaret for that specific scenario.

Type declaration

▸ (other): boolean

Parameters
NameType
othernull | NodeCaret<CaretDirection>
Returns

boolean

Inherited from

SiblingCaret.is

Defined in

packages/lexical/src/caret/LexicalCaret.ts:62


offset

Readonly offset: number

Defined in

packages/lexical/src/caret/LexicalCaret.ts:236


origin

Readonly origin: T

The origin node of this caret, typically this is what you will use in traversals

Inherited from

SiblingCaret.origin

Defined in

packages/lexical/src/caret/LexicalCaret.ts:51


remove

remove: () => this

Remove the getNodeAtCaret() node, if it exists

Type declaration

▸ (): this

Returns

this

Inherited from

SiblingCaret.remove

Defined in

packages/lexical/src/caret/LexicalCaret.ts:84


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
NameType
nodeLexicalNode
includeChildren?boolean
Returns

this

Inherited from

SiblingCaret.replaceOrInsert

Defined in

packages/lexical/src/caret/LexicalCaret.ts:92


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
NameTypeDescription
deleteCountnumberThe number of existing nodes to replace or delete
nodesIterable<LexicalNode>An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes
nodesDirection?CaretDirectionThe direction of the nodes iterable, defaults to 'next'
Returns

this

Inherited from

SiblingCaret.splice

Defined in

packages/lexical/src/caret/LexicalCaret.ts:100


type

Readonly type: "sibling"

sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)

Inherited from

SiblingCaret.type

Defined in

packages/lexical/src/caret/LexicalCaret.ts:53