fix: scroll command-bar suggestions by display width so wide characters stay visible#4135
Open
greymoth-jp wants to merge 1 commit into
Open
fix: scroll command-bar suggestions by display width so wide characters stay visible#4135greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
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.
The autocomplete suggestion strip in the info bar can scroll to the wrong offset when a suggestion contains full-width characters (CJK ideographs, kana, full-width forms), leaving the selected suggestion partly or fully off screen.
scrollToSuggestiontracks its column position withutil.CharacterCountInString, which counts characters, so a CJK ideograph counts as 1. The strip itself is drawn by display width:Displayadvances byrunewidth.RuneWidthper rune, andtotalSizealready sumsrunewidth.StringWidth(n). Once a suggestion is wider than its character count, the scroll math and the renderer disagree.Example: suggestions
["日本語テスト", "ok", "end"]with the second one selected, in a 14-column strip.日本語テストis 6 characters but 12 display columns, so the renderer drawsokat columns 13 to 15.scrollToSuggestionplaces it at column 7, keepshscrollat 0, andokis clipped at the right edge. Measuring by display width setshscrollto 2 andokis fully visible.Switching that line to
runewidth.StringWidth(n)matchestotalSizeand the renderer. ASCII-only suggestions are unchanged, since there character count equals display width.I confirmed the package builds and the
internal/utiltests pass.internal/displayhas no test files, so I checked the scroll offset against the renderer's true columns for the case above: wrong before, correct after, and unchanged for ASCII input.