Fix selection bug in code highlighting transform (#3405)

This commit is contained in:
Dominic Gannaway
2022-11-23 19:24:49 +00:00
committed by GitHub
parent 30f09a3419
commit 4ed1cba79c

View File

@ -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;
}