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

Fix merging text nodes after delete

startContainer is not necessarily a sibling to endContainer at this
point. endContainer is definitely at the right level of the hierarchy
so instead just get the previous sibling from this and merge with that
if it's also a text node.
This commit is contained in:
Neil Jenkins 2024-07-18 13:04:35 +10:00
parent 196f325fc0
commit 3def29e081

View file

@ -134,11 +134,12 @@ const extractContentsOfRange = (
}
// Merge text nodes if adjacent
if (startContainer instanceof Text && endContainer instanceof Text) {
startContainer.appendData(endContainer.data);
node = endContainer.previousSibling;
if (node && node instanceof Text && endContainer instanceof Text) {
endOffset = node.length;
node.appendData(endContainer.data);
detach(endContainer);
endContainer = startContainer;
endOffset = startOffset;
endContainer = node;
}
range.setStart(startContainer, startOffset);