Fix order on pasting story
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user