Fix order on pasting story

This commit is contained in:
Stefan Hardegger
2025-07-24 14:51:20 +02:00
parent d48e217cbb
commit a38812877a

View File

@@ -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();