Repository navigation
Implement Unicode-aware word motion (w/e/b/diw/ciw/de/db) - #296
Conversation
edtui's built-in word motions use is_ascii_alphanumeric(), causing CJK characters to be classified as Unknown (each character treated as its own word boundary). Replace with custom Unicode-aware implementations using char::is_alphanumeric() so Korean/CJK text is handled correctly. - Add char_class, skip_ws (cross-line), skip_ws_rev helpers - Add move_word_forward, move_word_backward, move_word_forward_to_end - Add select_inner_word for diw/ciw - Fix de to not delete trailing whitespace (remove extra MoveForward) - Fix db to use exclusive motion (don't include cursor char) - Fix w to skip leading whitespace when crossing lines - Fix b to find word start (not last char) when crossing lines - Remove insert-mode Alt+F/Alt+B word motions and keymap help entries
📝 WalkthroughWalkthroughRefactors editor word-motion into Unicode-aware helper functions, removes Alt+F/Alt+B insert-mode bindings and keymap entries, updates normal/visual mode transitions to call the new helpers, and adds extensive word-motion tests (including CJK) plus small Tester helpers for assertions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Glues Coverage Report
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tui/src/transitions/notebook/textarea.rs`:
- Around line 235-290: The recursive upward moves in move_word_backward_once
(calls to itself from the col==0 branch and the whitespace-at-col-0 branch after
skip_ws_rev) can cause deep recursion on many blank lines; refactor this
function to an iterative loop: use a while loop that moves idx/ editor.cursor up
by one row when at col 0 or when whitespace at col 0 instead of recursing,
reusing skip_ws_rev and the same char_class/backward-scan logic (Index2,
editor.lines, editor.cursor) until you find the word start or reach the buffer
start; ensure each iteration updates idx/cursor and continues rather than
calling move_word_backward_once.
🧹 Nitpick comments (2)
tui/tests/editor_cjk.rs (1)
8-23:setup()helper is duplicated fromeditor_word_motion.rs.This helper is identical to the one in
editor_word_motion.rs(lines 8–21). Consider extracting it intotester.rsas a shared method (e.g.,Tester::setup_editor_with_text) to avoid the duplication. Not blocking since test-file-level helpers are common.tui/src/transitions/notebook/textarea.rs (1)
122-132:skip_ws_reviterates beyond the logical stop point whenidx.colsaturates at 0.When all characters from
idx.coldown to 0 are whitespace,idx.colsaturates at 0 but the iterator continues visiting remaining characters (all of which are whitespace), callingsaturating_sub(1)as a no-op each time. The result is still correct (caller handles the "still on whitespace" case at lines 259-266), but the extra iterations are wasted work.An early
breakwhenidx.col == 0would short-circuit cleanly:Proposed fix
for ch in line.iter().rev().skip(skip) { if !ch.is_whitespace() { break; } + if idx.col == 0 { + break; + } idx.col = idx.col.saturating_sub(1); }
Avoids theoretical stack overflow on documents with many consecutive blank or whitespace-only lines.
Summary
is_ascii_alphanumeric(), causing CJK characters to each be treated as a separate word boundary. This replaces them with custom Unicode-aware implementations usingchar::is_alphanumeric().dedeleting trailing whitespace,dbincluding cursor char,wnot skipping leading whitespace on line crossings,bgoing to last char instead of word start on line crossings.Alt+F/Alt+Bword motions and their keymap help entries.Test plan
cargo clippy --all-targets -- -D warningspassescargo test --workspace— 71 tests pass (19 new: 8 CJK + 11 word motion)Summary by CodeRabbit
Improvements
Changes
Tests