mirror of
https://github.com/facebook/lexical.git
synced 2025-05-21 00:57:23 +08:00
Fix selection bug in code highlighting transform (#3405)
This commit is contained in:
@ -381,9 +381,7 @@ function updateAndRetainSelection(
|
||||
textOffset =
|
||||
anchorOffset +
|
||||
anchorNode.getPreviousSiblings().reduce((offset, _node) => {
|
||||
return (
|
||||
offset + ($isLineBreakNode(_node) ? 0 : _node.getTextContentSize())
|
||||
);
|
||||
return offset + _node.getTextContentSize();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -402,9 +400,10 @@ function updateAndRetainSelection(
|
||||
// If it was non-element anchor then we walk through child nodes
|
||||
// and looking for a position of original text offset
|
||||
node.getChildren().some((_node) => {
|
||||
if ($isTextNode(_node)) {
|
||||
const isText = $isTextNode(_node);
|
||||
if (isText || $isLineBreakNode(_node)) {
|
||||
const textContentSize = _node.getTextContentSize();
|
||||
if (textContentSize >= textOffset) {
|
||||
if (isText && textContentSize >= textOffset) {
|
||||
_node.select(textOffset, textOffset);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user