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 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.