fix(textinput): account for scroll offset in hardware Cursor() X position#1010
Open
syf2211 wants to merge 1 commit into
Open
fix(textinput): account for scroll offset in hardware Cursor() X position#1010syf2211 wants to merge 1 commit into
syf2211 wants to merge 1 commit into
Conversation
…tion Cursor() used m.Position() (absolute index) instead of the scroll-adjusted visible column (m.pos - m.offset), causing the hardware cursor to be placed at the wrong column when input text overflows the configured width. Fixes charmbracelet#1001
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
Fix
textinput.Model.Cursor()to use the scroll-adjusted visible column (m.pos - m.offset) instead of the absolute cursor position (m.Position()), matching howView()already renders the cursor.Fixes #1001
Motivation
When input text is wider than the configured width, the textinput scrolls horizontally.
View()correctly usesm.pos - m.offsetfor the visible cursor column, butCursor()used the absolute position. This caused the hardware cursor (used withSetVirtualCursor(false)) to appear at the wrong column when the input was scrolled.Changes
textinput/textinput.go: InCursor(), replacem.Position()withmax(0, m.pos-m.offset)when computingxOffset.textinput/textinput_test.go: AddTestCursorXAccountsForScrollOffset— sets a 30-character value in a width-20 input with the cursor at position 15 (offset=10, visible column=5) and assertsCursor().X == 7(visible column + prompt width).Tests
Notes
min(xOffset, m.width+promptWidth)clamp is unchanged.offset == 0), behavior is identical to before.