fix: scroll offset_x by visual width, not char count, in focus() - #16
Open
slaptijack wants to merge 1 commit into
Open
fix: scroll offset_x by visual width, not char count, in focus()#16slaptijack wants to merge 1 commit into
slaptijack wants to merge 1 commit into
Conversation
focus() compared the cursor's raw character-count column against the viewport width when deciding whether to scroll horizontally. For lines with double-width glyphs (CJK, emoji), character count under-estimates the true display width, so focus() could decide no scroll was needed while the cursor was actually off-screen — disagreeing with get_visible_cursor(), which already computes visual columns correctly via grapheme widths. focus() now computes cursor/offset_x visual columns the same way get_visible_cursor() does, and resolves scroll targets back to a char index via a new char_idx_for_visual_col() helper. Fixes vipmax#15
This was referenced Aug 27, 2026
slaptijack
added a commit
to slaptijack/human-exception
that referenced
this pull request
Aug 28, 2026
## Summary
- Qualifies the unconditional viewport guarantee in `docs/TUI_DESIGN.md`
("The vertical and horizontal viewport auto-scrolls to keep the cursor
visible...") with the accepted, temporary `ratatui-code-editor` 0.0.6
wide-glyph limitation already characterized in
`tests/editor_foundation_contract.rs`.
- Adds a new "Known limitation: wide-glyph cursor visibility" subsection
distinguishing affected behavior (long lines of wide/double-width glyphs
requiring horizontal scroll) from unaffected behavior (ASCII long lines,
short wide-glyph content, combining marks, exact Unicode round-trip),
each backed by an existing test.
- Links the upstream tracking issue
([vipmax/ratatui-code-editor#15](vipmax/ratatui-code-editor#15))
and proposed fix
([vipmax/ratatui-code-editor#16](vipmax/ratatui-code-editor#16)).
- Spells out the future resolution procedure (dependency-upgrade issue →
upgrade → flip the characterization assertion → verify via foundation
contract + Controller `TestBackend` → remove this doc section).
- Documentation-only; no source or test changes.
`known_limitation_wide_glyph_line_can_leave_cursor_offscreen_after_focus`
already fails conspicuously (per its own comment) once the upstream
behavior changes.
Closes #125
## Test plan
- [x] `cargo fmt --check`
- [x] `cargo clippy --locked --all-targets --all-features -- -D
warnings`
- [x] `cargo test --locked --all-targets --all-features`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Editor::focus()decided whether to scroll horizontally by comparing the cursor's raw character-count column against the viewport width, which under-counts the true display width of lines containing double-width glyphs (CJK, emoji). This could leave the cursor off-screen whilefocus()believed no scroll was needed, disagreeing withget_visible_cursor(), which already accounts for grapheme display width.focus()now computes the cursor's andoffset_x's visual columns the same wayget_visible_cursor()does (summing grapheme widths), and resolves scroll targets back to a character index via a newchar_idx_for_visual_col()helper.Fixes #15
Test plan
focus_scrolls_horizontally_for_wide_glyph_linesintests/input.rs, reproducing the issue's repro case (a 20-character line of界, 40-cell-wide viewport) — cursor now stays visible afterfocus().cargo test(33 tests across lib + integration suites) passes.cargo clippy --all-targetsshows no new warnings from this change.