Add a table (from the lexical table plugin) to LayoutNode.
Using the keyboard, navigate to the end of the table using right arrow and down arrow keys. Once the caret is on the right outer edge of the table, hit Down Arrow Key and then Enter key.
A paragraph should be created after the table node, within the LayoutNode.
I believe I can workaround the issue by defining my own "select" method on the element node such that when the user tries to select the element node, it inserts a paragraph node if needed.
select(anchorOffset?: number, focusOffset?: number): RangeSelection {
const selection = super.select(anchorOffset, focusOffset);
if (selection.anchor.key === this.__key || selection.focus.key === this.__key) {
// If the current node is selected, select either the first child or last child,
// but don't allow selection of the current node
if (anchorOffset === 0) {
// Insert paragraph at the beginning if needed
const firstChild = this.getFirstChild();
if (
!firstChild ||
(!$isParagraphNode(firstChild) &&
!$isTextNode(firstChild) &&
!firstChild.isInline())
) {
this.splice(0, 0, [$applyNodeReplacement($createParagraphNode())]);
}
return this.selectStart();
}
// Insert paragraph at the end if needed
const lastChild = this.getLastChild();
if (
!lastChild ||
(!$isParagraphNode(lastChild) && !$isTextNode(lastChild) && !lastChild.isInline())
) {
this.append($applyNodeReplacement($createParagraphNode()));
}
return this.selectEnd();
}
return selection;
}
If the element node cannot be selected, we won't enter that infinite loop
Lexical version: 0.14.5
Steps To Reproduce
LayoutNode
.LayoutNode
.splitNodeAtPoint
which callsnode.getParent()
which returns the root again.Link to code example:
LayoutNode
implementation:LayoutNode implementation
```ts import { $applyNodeReplacement, type DOMConversionFn, type DOMConversionMap, type EditorConfig, ElementNode, type LexicalNode, type SerializedElementNode, type Spread, } from 'lexical'; export type SerializedLayoutNode = Spread< { version: 1; }, SerializedElementNode >; const convertDivElement: DOMConversionFnThe current behavior
Infinite loop trying to insert a paragraph.
The expected behavior
A paragraph should be created after the table node, within the LayoutNode.
I believe I can workaround the issue by defining my own "select" method on the element node such that when the user tries to select the element node, it inserts a paragraph node if needed.
If the element node cannot be selected, we won't enter that infinite loop