fix(textinput): allow full placeholder display when width is 0#956
Open
Jah-yee wants to merge 2 commits intocharmbracelet:mainfrom
Open
fix(textinput): allow full placeholder display when width is 0#956Jah-yee wants to merge 2 commits intocharmbracelet:mainfrom
Jah-yee wants to merge 2 commits intocharmbracelet:mainfrom
Conversation
added 2 commits
April 15, 2026 00:12
Previously, the placeholder would only display the first character when Width() was small or unset. This was caused by allocating a rune slice with size m.Width()+1, which would truncate the placeholder text. Now we allocate the full placeholder text and display it properly regardless of the Width() setting. Fixes charmbracelet#779
The early return check incorrectly truncated the placeholder to only 1 character when Width was 0. Since the comment states 'if there is no width, the placeholder can be any length', we should always show the full placeholder when Width is 0. This removes the erroneous early return that was causing only the first character of the placeholder to be visible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Good day,
Summary
This PR fixes issue #950: textinput v2: 0 Width breaks placeholders
Problem
When
Width = 0is set on a textinput model with a placeholder, only the first character of the placeholder was displayed.The bug was caused by an erroneous early return check in
placeholderView():This check incorrectly truncated the placeholder to just 1 character when Width is 0 and placeholder length > 1.
Solution
Removed the incorrect early return. The comment in the code already states "if there is no width, the placeholder can be any length", which is the correct behavior for Width = 0.
Now when Width is 0, the full placeholder is displayed as expected.
Testing
Thank you for your work on this project. I hope this small fix is helpful. Please let me know if there's anything to adjust.
Warmly, RoomWithOutRoof