From eced5cbae455ea6d2c3f191868654413de906d5d Mon Sep 17 00:00:00 2001 From: tegwick Date: Sat, 25 Oct 2025 21:41:59 +0200 Subject: [PATCH] fix: prevent section jumping by preserving insertion position MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- markitect/document_manager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/markitect/document_manager.py b/markitect/document_manager.py index 2e4cfbab..4237b19a 100644 --- a/markitect/document_manager.py +++ b/markitect/document_manager.py @@ -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