Fix crash when editing non-ASCII text (#3) #23

Merged
eric merged 1 commit from eric/fix-3-non-ascii-input into master 2026-10-12 15:44:19 -05:00 AGit
Owner

Closes #3

Problem: text fields moved the cursor by characters but edited the text by byte position. Accented characters like é take two bytes, so typing Amélie and then moving the cursor or pressing Backspace could crash the app.

Fix:

  • New src/text_input.rs with one handle_key for cursor movement, Ctrl+word jumps, Home/End, Backspace, Delete and typing. The cursor is counted in characters.
  • The episode editor, the / filter and the new-series name all use it. This replaces three near-identical copies of the logic in handlers.rs (about 230 lines removed).
  • SeriesCreator and the episode editor shorten text to fit the screen by whole characters instead of slicing bytes.

Testing:

  • New tests/text_input_tests.rs edits "Amélie Poulain" with every key above.
  • Ran the real app in tmux with dummy videos: edited accented text in the / filter and the episode Title field with every key. Text and cursor position were right each time, and the app exited cleanly.
  • Full suite: 210 passed, 1 failed. The failure is test_buffer_clearing_performance, an existing timing test (#12).

🤖 Generated with Claude Code

https://claude.ai/code/session_01E2XefpQijvBcJBfgzuaoWA

Closes #3 **Problem:** text fields moved the cursor by characters but edited the text by byte position. Accented characters like `é` take two bytes, so typing `Amélie` and then moving the cursor or pressing Backspace could crash the app. **Fix:** - New `src/text_input.rs` with one `handle_key` for cursor movement, Ctrl+word jumps, Home/End, Backspace, Delete and typing. The cursor is counted in characters. - The episode editor, the `/` filter and the new-series name all use it. This replaces three near-identical copies of the logic in `handlers.rs` (about 230 lines removed). - `SeriesCreator` and the episode editor shorten text to fit the screen by whole characters instead of slicing bytes. **Testing:** - New `tests/text_input_tests.rs` edits "Amélie Poulain" with every key above. - Ran the real app in tmux with dummy videos: edited accented text in the `/` filter and the episode Title field with every key. Text and cursor position were right each time, and the app exited cleanly. - Full suite: 210 passed, 1 failed. The failure is `test_buffer_clearing_performance`, an existing timing test (#12). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01E2XefpQijvBcJBfgzuaoWA
Text fields moved the cursor by characters but edited the string by
byte offset, so typing something like "Amélie" and then moving the
cursor or pressing Backspace could panic on a char boundary.

Add a shared text_input::handle_key that keeps the cursor as a
character index and converts to a byte offset only when editing. The
episode editor, the / filter and the new-series name now all use it in
place of three copies of the same logic. SeriesCreator and the episode
editor truncate by characters instead of slicing bytes.

Closes #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2XefpQijvBcJBfgzuaoWA
eric merged commit 770b609ea1 into master 2026-10-12 15:44:19 -05:00
Sign in to join this conversation.
No reviewers
No labels
bug
chore
feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
spinach-dev/movies!23
No description provided.