Skip to content

Conversation

sebastianhuus
Copy link

Summary

  • Fixes placeholder text being truncated to first character on initial render
  • Resolves issue where placeholder displays correctly only after width is calculated

Problem

The placeholderView function in textinput.go was creating a rune slice with size m.Width+1. When m.Width is 0 during initial render, this created a slice of length 1, truncating multi-character placeholders to just their first character.

Solution

  • Changed slice allocation from m.Width+1 to max(len(m.Placeholder), m.Width+1) to ensure it can always hold the full placeholder
  • Updated early return condition to check len(m.Placeholder) instead of len(p)

Test plan

  • Verified fix resolves the truncation issue with gum input commands
  • Tested with long placeholder: "Enter your full name and email address here"
  • Tested with medium placeholder: "Your message here"
  • Tested with short placeholder: "Name"
  • Confirmed existing functionality remains intact

All tests show full placeholder text immediately on render, no more truncation.

Fixes #779

The placeholderView function incorrectly sized the rune slice using
m.Width+1, which created a slice of length 1 when Width was 0 during
initial render. This truncated multi-character placeholders to just
their first character.

Fixed by ensuring the slice is always large enough to hold the entire
placeholder text and updated the early return condition to check the
actual placeholder length.

Fixes charmbracelet#779

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@sebastianhuus
Copy link
Author

I also tested some various length placeholders. They all rendered properly with the caret highlighted on the first character and allowing input without a duplicate placeholder line.

Pre fix behavior:

pre fix old short placeholder old medium placeholder 2 old long placeholder

Post fix behavior:

post fix short placeholder medium placeholder long placeholder

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