Skip to content

fix(textinput): show full placeholder when Width is not set#988

Open
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/textinput-placeholder-truncated
Open

fix(textinput): show full placeholder when Width is not set#988
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/textinput-placeholder-truncated

Conversation

@troclaux
Copy link
Copy Markdown

Summary

Fixes #779: when Width is 0 (the default), only the first character of the placeholder was displayed.

Root cause

placeholderView allocated make([]rune, m.Width()+1) — a 1-element slice when Width is 0. After copy, only one rune was transferred. The subsequent guard m.Width() < 1 && len(p) <= 1 then triggered an early return, rendering only that single character.

Changes

  • textinput.go: allocate max(m.Width()+1, len(placeholderRunes)) so the full placeholder always fits; update the early-return condition to check len(placeholderRunes) <= 1 instead of len(p) <= 1.

Testing

  • New regression test TestPlaceholderFullRenderWithoutWidth verifies the full placeholder appears when Width is not set.
  • All existing tests pass.

Fixes #779

When Width is 0 (default), make([]rune, m.Width()+1) created a 1-element
slice causing copy to only transfer the first rune. The subsequent check
m.Width() < 1 && len(p) <= 1 then triggered an early return, rendering
only the first character of the placeholder.

Fix by allocating max(m.Width()+1, len(placeholderRunes)) so the full
placeholder always fits, and update the early-return condition to use
len(placeholderRunes) instead of len(p).

Fixes charmbracelet#779
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.

textinput: Initial letter only shown in placeholder

1 participant