Skip to content

textinput: render the full placeholder when Width is 0#976

Open
c-tonneslan wants to merge 1 commit into
charmbracelet:masterfrom
c-tonneslan:fix/textinput-zero-width-placeholder
Open

textinput: render the full placeholder when Width is 0#976
c-tonneslan wants to merge 1 commit into
charmbracelet:masterfrom
c-tonneslan:fix/textinput-zero-width-placeholder

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #950.

The placeholder buffer was sized to `Width()+1` runes, so a `Width` of 0 left exactly one slot. `copy(p, []rune(m.Placeholder))` silently dropped everything past the first character and `View()` then rendered a one-letter placeholder.

Size the buffer to the longer of `Width()+1` and the placeholder itself so all runes survive when the input has no explicit width. The width-set branch still trims to fit.

Added `TestPlaceholderZeroWidth` covering the regression.

The buffer for the placeholder runes was sized as Width()+1, so a
Width of 0 left exactly one slot. copy(p, []rune(m.Placeholder))
silently dropped everything past the first character and View() then
rendered a one-letter placeholder.

Size the buffer to the longer of Width+1 and the placeholder itself
so all runes survive when the input has no explicit width. The
"width set" branch still trims to fit; the unset branch now renders
the placeholder in full.

Closes charmbracelet#950.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@c-tonneslan c-tonneslan requested a review from meowgorithm as a code owner May 16, 2026 22:59
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