diff --git a/markitect/document_manager.py b/markitect/document_manager.py index 4237b19a..57246bc1 100644 --- a/markitect/document_manager.py +++ b/markitect/document_manager.py @@ -630,7 +630,8 @@ class DocumentManager: .edit-mode textarea { width: 100%; - min-height: 100px; + min-height: 60px; + max-height: 400px; font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace; border: 2px solid #007acc; border-radius: 6px; @@ -638,6 +639,9 @@ class DocumentManager: font-size: 14px; line-height: 1.5; resize: vertical; + overflow-y: auto; + box-sizing: border-box; + transition: height 0.15s ease; } .edit-mode textarea:focus { @@ -737,6 +741,39 @@ class DocumentManager: textarea.value = this.htmlToMarkdown(originalContent); textarea.className = 'edit-mode'; + // Auto-sizing function + const autoResize = () => { + // Temporarily disable transition for accurate measurement + const transition = textarea.style.transition; + textarea.style.transition = 'none'; + + // Reset height to measure scrollHeight + textarea.style.height = 'auto'; + + // Calculate ideal height based on content + const padding = 24; // 12px top + 12px bottom + const lineHeight = 21; // 14px font-size * 1.5 line-height + const minLines = 3; // Minimum of 3 lines + const maxLines = 20; // Maximum of 20 lines + + const contentHeight = textarea.scrollHeight; + const minHeight = (lineHeight * minLines) + padding; + const maxHeight = (lineHeight * maxLines) + padding; + + const newHeight = Math.max(minHeight, Math.min(maxHeight, contentHeight)); + textarea.style.height = newHeight + 'px'; + + // Re-enable transition + textarea.style.transition = transition; + }; + + // Auto-resize on input and paste + textarea.addEventListener('input', autoResize); + textarea.addEventListener('paste', () => setTimeout(autoResize, 10)); + + // Initial sizing after DOM update + setTimeout(autoResize, 20); + textarea.addEventListener('blur', () => { this.hasEdits = true; // Mark that edits have been made