Skip to content

textarea: reset viewport when auto-resized wrapped content fully fits#913

Open
yogirk wants to merge 1 commit intocharmbracelet:mainfrom
yogirk:textarea-autoresize-viewport-fix
Open

textarea: reset viewport when auto-resized wrapped content fully fits#913
yogirk wants to merge 1 commit intocharmbracelet:mainfrom
yogirk:textarea-autoresize-viewport-fix

Conversation

@yogirk
Copy link
Copy Markdown

@yogirk yogirk commented Mar 22, 2026

Summary

  • Bug: When a host app auto-resizes textarea height to match the current number of soft-wrapped rows (e.g. after each keypress), a stale viewport.YOffset can hide the first wrapped row — even though the entire buffer now fits within the visible area.
  • Fix: In repositionView(), if the total soft-wrapped line count fits within the viewport height, snap the viewport to top before applying cursor-following logic.
  • Test: Adds a keypress-driven autoresize regression test that simulates the real failure mode: type a long line one character at a time, auto-resize height after each keypress, and assert the first wrapped row remains visible.

Repro

  1. Create a textarea with a constrained width and height of 1
  2. Type a long line one keypress at a time
  3. After each keypress, set the textarea height to the current soft-wrapped row count
  4. Observe the first wrapped row disappears even though the content fully fits

Test plan

  • New test TestAutoResizeKeepsFirstSoftWrappedRowVisible passes
  • All existing textarea tests pass
  • Full module go test ./... passes

When a host app auto-resizes textarea height to match the current
number of soft-wrapped rows, a stale viewport offset could hide the
first wrapped row even though the full content fits.

Fix repositionView to snap the viewport to top when all soft-wrapped
rows fit within the current textarea height. Add a regression test
that simulates keypress-driven autoresize.
@yogirk yogirk requested a review from aymanbagabas as a code owner March 22, 2026 09:19
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.

1 participant