0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Remove multiple adjacent empty text nodes

Fix the loop condition so this will remove multiple adjacent empty
text nodes if necessary.
This commit is contained in:
Neil Jenkins 2023-02-20 09:57:31 +11:00
parent 9f258f2561
commit 4306cecb6e

View file

@ -48,22 +48,23 @@ const moveRangeBoundariesDownTree = (range: Range): void => {
if (!child || isLeaf(child)) {
if (startOffset) {
child = startContainer.childNodes[startOffset - 1];
let prev = child.previousSibling;
if (child instanceof Text) {
// Need a new variable to satisfy TypeScript's type checker
// for some reason.
let textChild: Text = child;
// If we have an empty text node next to another text node,
// just skip and remove it.
let prev: ChildNode | null;
while (
child instanceof Text &&
!child.length &&
prev &&
!textChild.length &&
(prev = textChild.previousSibling) &&
prev instanceof Text
) {
child.remove();
child = prev;
continue;
textChild.remove();
textChild = prev;
}
if (child instanceof Text) {
startContainer = child;
startOffset = child.data.length;
startContainer = textChild;
startOffset = textChild.data.length;
}
}
break;