From a38812877aaf7683b8be2c7d1f07c98000cabe00 Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Thu, 24 Jul 2025 14:51:20 +0200 Subject: [PATCH] Fix order on pasting story --- frontend/src/components/stories/RichTextEditor.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/stories/RichTextEditor.tsx b/frontend/src/components/stories/RichTextEditor.tsx index 7a33cc4..4005d58 100644 --- a/frontend/src/components/stories/RichTextEditor.tsx +++ b/frontend/src/components/stories/RichTextEditor.tsx @@ -148,11 +148,15 @@ export default function RichTextEditor({ const tempDiv = document.createElement('div'); tempDiv.innerHTML = sanitizedHtml; - // Insert the nodes from the temporary container + // Create a document fragment to insert all nodes at once + const fragment = document.createDocumentFragment(); while (tempDiv.firstChild) { - range.insertNode(tempDiv.firstChild); + fragment.appendChild(tempDiv.firstChild); } + // Insert the entire fragment at once to preserve order + range.insertNode(fragment); + // Move cursor to end of inserted content range.collapse(false); selection.removeAllRanges();