mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix(textinput): Placeholder No Longer Changes Width + Paste Calculation (#451)
* Fix pasting calculations Available length calculation now correctly trims pasted text. * fix(textInput): Width padding added when placeholder is used When `placeholder` is set, padding from `Width` was not added within the `placeholderView()` function. * Adding missing 'm.' * Maintain Width no matter placeholder size delta * Fixed Math * Added Comments * fix: lint --------- Co-authored-by: Donovan Hubbard <37090676+donovanhubbard@users.noreply.github.com> Co-authored-by: Maas Lalani <maas@lalani.dev>
This commit is contained in:
co-authored by
Donovan Hubbard
Maas Lalani
parent
fc50558f4b
commit
f36aa3c4b5
+24
-3
@@ -297,7 +297,7 @@ func (m *Model) insertRunesFromUserInput(v []rune) {
|
|||||||
// If there's not enough space to paste the whole thing cut the pasted
|
// If there's not enough space to paste the whole thing cut the pasted
|
||||||
// runes down so they'll fit.
|
// runes down so they'll fit.
|
||||||
if availSpace < len(paste) {
|
if availSpace < len(paste) {
|
||||||
paste = paste[:len(paste)-availSpace]
|
paste = paste[:availSpace]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,8 +713,29 @@ func (m Model) placeholderView() string {
|
|||||||
m.Cursor.SetChar(string(p[:1]))
|
m.Cursor.SetChar(string(p[:1]))
|
||||||
v += m.Cursor.View()
|
v += m.Cursor.View()
|
||||||
|
|
||||||
// The rest of the placeholder text
|
// If the entire placeholder is already set and no padding is needed, finish
|
||||||
v += style(string(p[1:]))
|
if m.Width < 1 && len(p) <= 1 {
|
||||||
|
return m.PromptStyle.Render(m.Prompt) + v
|
||||||
|
}
|
||||||
|
|
||||||
|
// If Width is set then size placeholder accordingly
|
||||||
|
if m.Width > 0 {
|
||||||
|
// available width is width - len + cursor offset of 1
|
||||||
|
minWidth := lipgloss.Width(m.Placeholder)
|
||||||
|
availWidth := m.Width - minWidth + 1
|
||||||
|
|
||||||
|
// if width < len, 'subtract'(add) number to len and dont add padding
|
||||||
|
if availWidth < 0 {
|
||||||
|
minWidth += availWidth
|
||||||
|
availWidth = 0
|
||||||
|
}
|
||||||
|
// append placeholder[len] - cursor, append padding
|
||||||
|
v += style(string(p[1:minWidth]))
|
||||||
|
v += style(strings.Repeat(" ", availWidth))
|
||||||
|
} else {
|
||||||
|
// if there is no width, the placeholder can be any length
|
||||||
|
v += style(string(p[1:]))
|
||||||
|
}
|
||||||
|
|
||||||
return m.PromptStyle.Render(m.Prompt) + v
|
return m.PromptStyle.Render(m.Prompt) + v
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user