From 752a42d917d6141178a8a01b71f4eea8b645dcde Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 20 Dec 2023 11:13:43 +1100 Subject: [PATCH] Fix Firefox cursor position bug after paste We merge a faux block with contents from after a split point when inserting HTML. The merge function presumes this block has already had fixCursor run on it to ensure we add the
s some browsers need to support correct cursor focusing. Fixes #451 --- source/node/MergeSplit.ts | 7 +++++-- source/range/InsertDelete.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/node/MergeSplit.ts b/source/node/MergeSplit.ts index 0b1a4be..4e8f5fe 100644 --- a/source/node/MergeSplit.ts +++ b/source/node/MergeSplit.ts @@ -37,9 +37,12 @@ const fixCursor = (node: Node): Node => { fixer = document.createTextNode(''); } } - } else if (node instanceof Element && !node.querySelector('BR')) { + } else if ( + (node instanceof Element || node instanceof DocumentFragment) && + !node.querySelector('BR') + ) { fixer = createElement('BR'); - let parent: Element = node; + let parent: Element | DocumentFragment = node; let child: Element | null; while ((child = parent.lastElementChild) && !isInline(child)) { parent = child; diff --git a/source/range/InsertDelete.ts b/source/range/InsertDelete.ts index 6e0e621..c31c069 100644 --- a/source/range/InsertDelete.ts +++ b/source/range/InsertDelete.ts @@ -425,6 +425,7 @@ const insertTreeFragmentIntoRange = ( // Insert inline content saved from before. if (blockContentsAfterSplit && block) { const tempRange = range.cloneRange(); + fixCursor(blockContentsAfterSplit); mergeWithBlock(block, blockContentsAfterSplit, tempRange, root); range.setEnd(tempRange.endContainer, tempRange.endOffset); }