Skip to content

fix(textinput): cap suggestion completion to input width - #1055

Open
timatigoogl3-code wants to merge 1 commit into
charmbracelet:mainfrom
timatigoogl3-code:fix/textinput-suggestion-width
Open

timatigoogl3-code wants to merge 1 commit into
charmbracelet:mainfrom
timatigoogl3-code:fix/textinput-suggestion-width

Conversation

@timatigoogl3-code

Copy link
Copy Markdown

Fix #812.

When suggestions are shown, the rendered completion tail is not bounded by the input width. With a value of `hel` and a long suggestion, the line rendered 69 visible cells with a width of 20, overflowing the space given to the textinput.

@timatigoogl3-code

Copy link
Copy Markdown
Author

Notes for the reviewer:

  • Root cause: completionView() rendered the whole suggestion tail without bounding it to the input width, and the padding block did not account for an already rendered completion.
  • Fix: completionView(offset, maxWidth) truncates the tail via ansi.Truncate; padding is now width+1 - valueWidth - cursor - completionWidth.
  • Regression test: Test_ViewRespectsWidthWithSuggestions. Without the fix it renders 69 cells at width 20; with the fix it renders 23 (prompt 2 + width 20 + cursor 1).
  • Ran go test ./... — all green; gofmt/vet clean on the changed files.

(Changes authored with AI assistance; happy to adjust to the project's conventions.)

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 overflows set width

2 participants