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:
parent
9f258f2561
commit
4306cecb6e
1 changed files with 16 additions and 15 deletions
|
@ -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 we have an empty text node next to another text node,
|
||||
// just skip and remove it.
|
||||
while (
|
||||
child instanceof Text &&
|
||||
!child.length &&
|
||||
prev &&
|
||||
prev instanceof Text
|
||||
) {
|
||||
child.remove();
|
||||
child = prev;
|
||||
continue;
|
||||
}
|
||||
if (child instanceof Text) {
|
||||
startContainer = child;
|
||||
startOffset = child.data.length;
|
||||
// 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 (
|
||||
!textChild.length &&
|
||||
(prev = textChild.previousSibling) &&
|
||||
prev instanceof Text
|
||||
) {
|
||||
textChild.remove();
|
||||
textChild = prev;
|
||||
}
|
||||
startContainer = textChild;
|
||||
startOffset = textChild.data.length;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue