Repository navigation
Description
Problem Statement
When users click on display text to start editing, the cursor position is inaccurate due to markdown syntax characters that are added/removed during the display ↔ edit mode transition.
User-Reported Issue
Original Problem: "when I click on a text content of a node, my pointer is where the cursor should be positioned. However, since the edit mode of the contenteditable could contain syntax, the extra characters can misplace the cursor to another part of the string."
Example: Clicking between 'e' and 'S' in display text "Welcome to NodeSpace" results in cursor positioned at "# Welcome to Nod|eSpace" instead of "# Welcome to Node|Space" in edit mode.
Acceptance Criteria
Core Functionality
- Click at start of text → cursor positions at character 0
- Click between characters → cursor lands within 1-2 characters of click point
- Click at end of text → cursor positions at final character
- Accurate positioning across different font sizes (H1=2rem, H2=1.5rem, normal text)
- Multi-line content positioning works correctly
- Unicode characters and emojis handled properly
Markdown Syntax Support
- Header syntax: "# Welcome" → click positioning accounts for "# " prefix
- Bold formatting: "text" → click positioning maps through formatting markers
- Italic formatting: "text" → click positioning handles single asterisks
- Nested formatting: "bold+italic" → click positioning handles complex nesting
- Mixed content: Headers with inline formatting work correctly
Performance Requirements
- Position calculation completes in < 50ms
- Memory overhead is minimal (no parallel DOM structures)
- Cross-browser compatibility (Chrome, Firefox, Safari)
User Experience
- Double-click text selection behavior preserved
- Triple-click selection behavior preserved
- No interference with existing text editing functionality
- Graceful fallback when positioning APIs unavailable
Technical Approach
Pre-calculation Strategy
Calculate cursor position BEFORE syntax transformation to avoid coordinate mismatch:
- Capture click coordinates during mousedown event
- Calculate character position using browser APIs (, )
- Map display position to markdown position using character-by-character algorithm
- Apply calculated position after syntax is shown in edit mode
Implementation Components
- ContentEditableController enhancement with positioning methods
- Character mapping algorithm for position translation
- Browser API integration with fallback support
- Event handling that preserves existing functionality
Definition of Done
- Precise cursor positioning implemented and working
- All acceptance criteria met and verified
- Comprehensive test coverage (unit tests for positioning algorithm)
- Performance benchmarks meet requirements
- Cross-browser compatibility verified
- Integration with existing text editing architecture
- Documentation updated with implementation details
Priority
High - Critical UX issue affecting core text editing experience
Labels
enhancement, text-editor, ux, high-priority
References
- Related to overall text editor architecture enhancement
- Builds on ContentEditableController foundation
- Part of NodeSpace precision editing experience improvements
Activity
Issue #81: Precision Cursor Positioning + Complete Design System
Issue #81: Precision Cursor Positioning + Complete Design System
Issue #81: Precision Cursor Positioning + Complete Design System