fix: prevent section jumping by preserving insertion position
Fixed critical positioning issue where split sections would jump to end of document instead of staying at their original location. Problem: - appendChild() was adding new sections at end of parent container - Split sections appeared at bottom of document, not at edit location - Disrupted document flow and user experience Solution: - Remember original position with nextSibling before removal - Use insertBefore(wrapper, nextSibling) for correct positioning - New sections now appear exactly where original section was located - Maintains proper document order and reading flow This ensures that when you split a paragraph by adding empty lines, the resulting sections stay in their logical position within the document structure. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -748,11 +748,12 @@ class DocumentManager:
|
||||
// Multiple paragraphs - create separate sections
|
||||
const parentNode = section.parentNode;
|
||||
const sectionIndex = section.getAttribute('data-section');
|
||||
const nextSibling = section.nextSibling; // Remember position
|
||||
|
||||
// Remove the original section
|
||||
parentNode.removeChild(section);
|
||||
|
||||
// Create separate sections for each paragraph
|
||||
// Create separate sections for each paragraph and insert at correct position
|
||||
paragraphs.forEach((paragraph, index) => {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = marked.parse(paragraph.trim());
|
||||
@@ -760,8 +761,8 @@ class DocumentManager:
|
||||
wrapper.setAttribute('data-section', sectionIndex + '_' + index);
|
||||
wrapper.setAttribute('data-edited', 'true');
|
||||
|
||||
// Insert each new section
|
||||
parentNode.appendChild(wrapper);
|
||||
// Insert at the correct position (before nextSibling)
|
||||
parentNode.insertBefore(wrapper, nextSibling);
|
||||
});
|
||||
} else {
|
||||
// Single content block - create one wrapper
|
||||
|
||||
Reference in New Issue
Block a user