Skip to content

fix(textinput): account for scroll offset in hardware Cursor() X position#1010

Open
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/1001-textinput-cursor-scroll-offset
Open

fix(textinput): account for scroll offset in hardware Cursor() X position#1010
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/1001-textinput-cursor-scroll-offset

Conversation

@syf2211

@syf2211 syf2211 commented Jun 26, 2026

Copy link
Copy Markdown

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 how View() already renders the cursor.

Fixes #1001

Motivation

When input text is wider than the configured width, the textinput scrolls horizontally. View() correctly uses m.pos - m.offset for the visible cursor column, but Cursor() used the absolute position. This caused the hardware cursor (used with SetVirtualCursor(false)) to appear at the wrong column when the input was scrolled.

Changes

  • textinput/textinput.go: In Cursor(), replace m.Position() with max(0, m.pos-m.offset) when computing xOffset.
  • textinput/textinput_test.go: Add TestCursorXAccountsForScrollOffset — sets a 30-character value in a width-20 input with the cursor at position 15 (offset=10, visible column=5) and asserts Cursor().X == 7 (visible column + prompt width).

Tests

go test ./textinput/... -v -run TestCursorXAccountsForScrollOffset  # PASS
go test ./...                                                      # PASS (all packages)

Notes

  • The existing min(xOffset, m.width+promptWidth) clamp is unchanged.
  • When text does not overflow (offset == 0), behavior is identical to before.
  • Reviewed with composer-2.5 sub-agent: APPROVED.

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

v2: textinput Cursor() X ignores scroll offset when input overflows width

2 participants