mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -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 (!child || isLeaf(child)) {
|
||||||
if (startOffset) {
|
if (startOffset) {
|
||||||
child = startContainer.childNodes[startOffset - 1];
|
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,
|
// If we have an empty text node next to another text node,
|
||||||
// just skip and remove it.
|
// just skip and remove it.
|
||||||
|
let prev: ChildNode | null;
|
||||||
while (
|
while (
|
||||||
child instanceof Text &&
|
!textChild.length &&
|
||||||
!child.length &&
|
(prev = textChild.previousSibling) &&
|
||||||
prev &&
|
|
||||||
prev instanceof Text
|
prev instanceof Text
|
||||||
) {
|
) {
|
||||||
child.remove();
|
textChild.remove();
|
||||||
child = prev;
|
textChild = prev;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (child instanceof Text) {
|
startContainer = textChild;
|
||||||
startContainer = child;
|
startOffset = textChild.data.length;
|
||||||
startOffset = child.data.length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue