Skip to main content

Interface: ChildCaret<T, D>

lexical.ChildCaret

A ChildCaret points from an origin ElementNode towards its first or last child.

Type parameters

NameType
Textends ElementNode = ElementNode
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

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

BaseCaret.getAdjacentCaret

Defined in

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


getChildCaret

getChildCaret: () => this

Return this, the ChildCaret is already a child caret of its origin

Type declaration

▸ (): this

Returns

this

Defined in

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


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

Defined in

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


getLatest

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

Get a new caret with the latest origin pointer

Type declaration

▸ (): ChildCaret<T, D>

Returns

ChildCaret<T, D>

Defined in

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


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

BaseCaret.getNodeAtCaret

Defined in

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


getParentAtCaret

getParentAtCaret: () => T

Get the ElementNode that is the logical parent (origin for ChildCaret, origin.getParent() for SiblingCaret)

Type declaration

▸ (): T

Returns

T

Overrides

BaseCaret.getParentAtCaret

Defined in

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


getParentCaret

getParentCaret: (mode?: RootMode) => null | SiblingCaret<T, D>

Type declaration

▸ (mode?): null | SiblingCaret<T, D>

Parameters
NameType
mode?RootMode
Returns

null | SiblingCaret<T, D>

Defined in

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


getSiblingCaret

getSiblingCaret: () => SiblingCaret<T, D>

Get a new SiblingCaret with this same node

Type declaration

▸ (): SiblingCaret<T, D>

Returns

SiblingCaret<T, D>

Inherited from

BaseCaret.getSiblingCaret

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
NameType
nodeLexicalNode
Returns

this

Inherited from

BaseCaret.insert

Defined in

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


isSameNodeCaret

isSameNodeCaret: (other: undefined | null | PointCaret<CaretDirection>) => other is ChildCaret<T, D>

Retun true if other is a ChildCaret with the same origin (by node key comparion) and direction.

Type declaration

▸ (other): other is ChildCaret<T, D>

Parameters
NameType
otherundefined | null | PointCaret<CaretDirection>
Returns

other is ChildCaret<T, D>

Defined in

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


isSamePointCaret

isSamePointCaret: (other: undefined | null | PointCaret<CaretDirection>) => other is ChildCaret<T, D>

Retun true if other is a ChildCaret with the same origin (by node key comparion) and direction.

Type declaration

▸ (other): other is ChildCaret<T, D>

Parameters
NameType
otherundefined | null | PointCaret<CaretDirection>
Returns

other is ChildCaret<T, D>

Defined in

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


origin

Readonly origin: T

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

Inherited from

BaseCaret.origin

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

BaseCaret.remove

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

this

Inherited from

BaseCaret.replaceOrInsert

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

BaseCaret.splice

Defined in

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


type

Readonly type: "child"

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

BaseCaret.type

Defined in

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