Bug: spliceText throws error on parameter modification in LexicalSelection
Lexical version: v0.19.0+git
Steps To Reproduce
- Edit line 1155
LexicalSelection.tsfromfirstNode.spliceText(firstPoint.offset, del, '', true);tofirstNode.spliceText(firstPoint.offset, del, '', false); //changing moveSelection=false - select any plain text and click
insert code block - delete character from the end of the code block
- i suspect the same behavior will happen to all elements with OuterTag
Link to code example: this bug is easy to reproduce using clone of the git
...
if (firstNode === lastNode && $isTextNode(firstNode)) {
const del = Math.abs(focus.offset - anchor.offset);
firstNode.spliceText(firstPoint.offset, del, '', false);
fixText(firstNode, del);
return;
}
...
The current behavior
changing the value of moveSelection throws error
IndexSizeError: Failed to execute 'setBaseAndExtent' on 'Selection': The offset 11 is larger than the node's length (10).
at updateDOMSelection (LexicalSelection.ts:2813:18)
at $commitPendingUpdates (LexicalUpdates.ts:627:9)
at LexicalUpdates.ts:1016:9
The expected behavior
I am new to lexical, i do not have any information when or where moveSelection is important
Impact of fix
It will be important to fix if someone decided to make their custom LexicalSelection.ts or LexicalTextNode.ts
I think it's expected behavior to get errors when you make modifications to the internals of a library without really understanding what's going on. If you can demonstrate some unexpected behavior when using the unmodified library in a normal way then you should open a new issue.
ah yes! thank you for swift response, i forgot that spliceText is not exclusively for deleting text/char