facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

Consider DecoratorNode in $insertNodeToNearestRoot #5949

Open LvChengbin opened 3 weeks ago

LvChengbin commented 3 weeks ago

DecoratorNode is not treated as ElementNode from this commit (https://github.com/facebook/lexical/pull/5371) on, but In $insertNodeToNearestRoot method, getTopLevelElementOrThrow is called if the selection is not a range selection. It causes error while the focus node is a DecoratorNode.

https://github.com/facebook/lexical/blob/686217de2d88a428eae3c7fd4159ef28117e0861/packages/lexical-utils/src/index.ts#L473

And another feature in this method should which I think it should be modified is checking empty after splitting node in range selection, otherwise it may create one more empty line.

Another question is why does this method end with inserting another paragraph node?