Repository navigation
Closed
Description
Problem
Current contenteditable-based editor has critical state synchronization bugs:
- Markdown syntax lost on focus/blur/input events
originalContentvs DOMinnerHTMLsync issues- Multiline content losing formatting
- Complex cursor positioning with markdown offsets
- Each fix breaks other functionality
Root cause: Maintaining two representations (DOM HTML + markdown string) simultaneously.
Solution
Adopt Logseq's proven approach: textarea for editing + separate rendering on blur
Architecture Change
Current (contenteditable):
- Dual state:
originalContent(markdown) +element.innerHTML(formatted HTML) - Real-time inline formatting (bold/italic visible while typing)
- Complex synchronization logic
- ~2000+ lines in ContentEditableController
New (textarea):
- Single source of truth:
textarea.value(raw markdown) - Inline syntax visible during edit mode
- Formatted rendering only on blur (syntax hidden)
- ~500-800 lines (simpler TextareaController)
Key Benefits
- Zero synchronization bugs - textarea.value is the only state
- Native cursor APIs -
selectionStart/selectionEndinstead of DOM traversal - Simpler testing - string assertions instead of DOM queries
- Better AI integration - agents work with plain markdown
- Proven approach - Used by Logseq (millions of users)
Visual Changes
Editing mode:
- Inline markdown syntax visible:
**bold**,*italic* - Block syntax triggers node type conversion:
#→ HeaderNode
View mode (blur):
- Inline syntax hidden, formatting rendered: bold, italic
- Block nodes styled appropriately (headers, quotes, code blocks)
Preserved Functionality
- ✅ Enter creates new nodes
- ✅ Backspace merges/deletes nodes
- ✅ Arrow navigation within/between nodes
- ✅ Slash commands
- ✅ @ mentions
- ✅ Keyboard shortcuts
- ✅ Clean UI (no borders, minimal padding)
- ✅ Auto-resize height
Migration Steps
- Create TextareaController (replaces ContentEditableController)
- Update BaseNode to use
<textarea>instead of<div contenteditable> - Update keyboard commands for string operations
- Implement markdown rendering on blur
- Adapt cursor positioning for view→edit transitions
- Update ALL existing tests (see Testing Requirements below)
- Delete ContentEditableController (~580 lines removed)
Acceptance Criteria
- TextareaController implements all keyboard commands
- Node creation/deletion works identically
- Arrow navigation works within/between nodes
- Click on view mode positions cursor correctly in edit mode
- Slash commands work
- @ mentions work
- Inline markdown renders on blur (syntax hidden)
- All existing tests updated and passing (see Testing Requirements)
- Code review via
/pragmatic-code-reviewpasses - No contenteditable code remains
- Performance: handles 100+ nodes smoothly
Testing Requirements
CRITICAL: All existing tests must be updated for textarea
Tests affected (~50+ test files):
- ContentEditableController tests → TextareaController tests (complete rewrite)
- Keyboard command tests (update element queries)
- Integration tests (update DOM queries and assertions)
Changes needed:
- Replace
querySelector('[contenteditable]')withquerySelector('textarea') - Replace
element.innerHTMLassertions withtextarea.valueassertions - Simpler assertions (string comparisons instead of HTML parsing)
- Tests should be easier to write and more reliable
All tests must pass before PR is ready for review.
References
- Analysis:
docs/architecture/research/logseq-editor-analysis.md - Design system:
docs/design-system/components.html
Activity
Add Logseq editor architecture analysis
Fix arrow key navigation and eliminate layout jerking in textarea mig…
Update keyboard commands and registry for TextareaController
Fix data loss on refresh + remove dead code from textarea migration
Fix cursor positioning on Enter + create CursorPositioningService
Refactor focus management to single source of truth (FocusManager)
Fix FocusManager integration for node split/merge operations
Fix markdown formatting shortcuts (Cmd+B, Cmd+I)
Fix test infrastructure for textarea migration (#274) - WIP
Fix TypeScript errors and remove obsolete headerLevel prop (#274)
Remove outdated tests and update plugin expectations (#274)
19 remaining items
Implement CodeBlockNode component with textarea-based editing (#276) (#…
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)
Add Logseq editor architecture analysis
Migrate to textarea-based editor (Logseq approach) (#280)
Document textarea-based editor architecture (#274)
Implement HeaderNode component with textarea (#284)
Implement CodeBlockNode component with textarea-based editing (#276) (#…
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)
Migrate to textarea-based editor (Logseq approach) (#280)
Implement HeaderNode component with textarea (#284)
Implement CodeBlockNode component with textarea-based editing (#276) (#…
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)