feat(tui): implement word wrapping in Editor component

Previously, the Editor component used character-level (grapheme-level)
wrapping, which broke words mid-character at line boundaries. This
created an ugly visual experience when typing or pasting long text.

Now the Editor uses word-aware wrapping:
- Wraps at word boundaries when possible
- Falls back to character-level wrapping for tokens wider than the
  available width (e.g., long URLs)
- Strips leading whitespace at line starts
- Preserves multiple spaces within lines

Added wordWrapLine() helper function that tokenizes text into words
and whitespace runs, then builds chunks that fit within the specified
width while respecting word boundaries.

Also updated buildVisualLineMap() to use the same word wrapping logic
for consistent cursor navigation.

Added tests for:
- Word boundary wrapping
- Leading whitespace stripping
- Long token (URL) character-level fallback
- Multiple space preservation
- Edge cases (empty string, exact fit)
This commit is contained in:
Nick Seelert 2025-12-30 23:05:35 -05:00
parent b123df5fab
commit dde5f25170
3 changed files with 309 additions and 70 deletions

View file

@ -12,6 +12,7 @@
### Changed
- README.md completely rewritten with accurate component documentation, theme interfaces, and examples
- Editor component now uses word wrapping instead of character-level wrapping for better readability
### Fixed