mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Handle empty nodes in moveRangeBoundariesDownTree
Empty text nodes next to another text node can always be safely eliminated.
This commit is contained in:
parent
e4ae7c2b81
commit
b85754ca50
1 changed files with 14 additions and 1 deletions
|
@ -44,10 +44,23 @@ const moveRangeBoundariesDownTree = (range: Range): void => {
|
|||
let { startContainer, startOffset, endContainer, endOffset } = range;
|
||||
|
||||
while (!(startContainer instanceof Text)) {
|
||||
let child = startContainer.childNodes[startOffset];
|
||||
let child: ChildNode | null = startContainer.childNodes[startOffset];
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue