Fix scroll position when typing in long notes

- Preserve textarea scroll position during auto-resize in onChange handler
- Prevents view from jumping to top when typing below the fold
This commit is contained in:
drelich
2026-03-25 23:36:02 +01:00
parent cb7a8d8276
commit 0a6ecd25da

View File

@@ -861,9 +861,11 @@ export function NoteEditor({ note, onUpdateNote, onUnsavedChanges, categories, i
value={localContent} value={localContent}
onChange={(e) => { onChange={(e) => {
handleContentChange(e.target.value); handleContentChange(e.target.value);
// Auto-resize textarea to fit content // Auto-resize textarea to fit content while preserving scroll position
const scrollTop = e.target.scrollTop;
e.target.style.height = 'auto'; e.target.style.height = 'auto';
e.target.style.height = e.target.scrollHeight + 'px'; e.target.style.height = e.target.scrollHeight + 'px';
e.target.scrollTop = scrollTop;
}} }}
className="w-full resize-none border-none outline-none focus:ring-0 bg-transparent text-gray-900 dark:text-gray-100 overflow-hidden" className="w-full resize-none border-none outline-none focus:ring-0 bg-transparent text-gray-900 dark:text-gray-100 overflow-hidden"
style={{ fontSize: `${editorFontSize}px`, lineHeight: '1.6', minHeight: '100%', fontFamily: editorFont }} style={{ fontSize: `${editorFontSize}px`, lineHeight: '1.6', minHeight: '100%', fontFamily: editorFont }}