Skip to content

fix(tui): keep text offsets on character boundaries - #1164

Open
lexoliu wants to merge 1 commit into
mainfrom
fix/1160-str-offsets
Open

lexoliu wants to merge 1 commit into
mainfrom
fix/1160-str-offsets

Conversation

@lexoliu

@lexoliu lexoliu commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Cursors, selection columns and truncation limits counted chars and then sliced the &str with that count as a byte offset, so editing or truncating Chinese, Japanese, Korean or emoji text misplaced the caret or cut mid-character. Cursors and selections are now byte offsets on grapheme boundaries (the composer and config editors share the grapheme helpers), previews cut by display width, and character limits use a bounded char_indices walk; no .chars().count() or .chars().nth() is left outside tests. An audit of computed &str slices fixed the ones whose bound could split a character: scheduler output, the context report's section span (which also panicked on a close tag before its open) and the picker's case-insensitive match against lowercased text. The paste threshold is now one character-based check that the TUI and the prompt block share.

Editing, moving, deleting and rendering are tested with Chinese, Japanese, Korean and a modified emoji; the TUI, paste, import, scheduler, artifact, chat and context-report tests pass and clippy is clean with -D warnings.

Closes #1160

Cursors, selections and truncation limits counted chars with
.chars().count(), then sliced the str with that count as if it were a byte
offset, so editing or truncating Chinese, Japanese, Korean or emoji text
misplaced the caret or cut mid-character. Cursors and selection columns are now
byte offsets kept on grapheme boundaries, previews cut by display width, and
character limits are found with a bounded char_indices walk. Slices whose bound
could split a character (scheduler output, the context report's section span,
the picker's case-insensitive match) now land on boundaries, and the paste
threshold is one check shared by the TUI and the prompt block.

Closes #1160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Char counting and unchecked str slicing in cursors and truncation

1 participant