From 3def29e0818c9c9aed6bd2e220dea090cc85da09 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 18 Jul 2024 13:04:35 +1000 Subject: [PATCH] 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. --- source/range/InsertDelete.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/range/InsertDelete.ts b/source/range/InsertDelete.ts index c31c069..c443bf9 100644 --- a/source/range/InsertDelete.ts +++ b/source/range/InsertDelete.ts @@ -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);