From d7e563b9ee8bb0f24cc1160cbbcc887ab9adaaa7 Mon Sep 17 00:00:00 2001 From: Dolev Hadar <6196971+dlvhdr@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:11:18 +0300 Subject: [PATCH] fix(branches): search placeholder (#434) --- ui/components/reposection/reposection.go | 2 +- ui/components/search/search.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/components/reposection/reposection.go b/ui/components/reposection/reposection.go index fca5076a..0de43687 100644 --- a/ui/components/reposection/reposection.go +++ b/ui/components/reposection/reposection.go @@ -53,7 +53,7 @@ func NewModel( LastUpdated: lastUpdated, }, ) - m.SearchBar = search.NewModel(ctx, search.SearchOptions{Placeholder: "Search branches"}) + m.SearchBar = search.NewModel(ctx, search.SearchOptions{Placeholder: "Search branches..."}) m.SearchValue = "" m.repo = &git.Repo{Branches: []git.Branch{}} m.Branches = []branch.Branch{} diff --git a/ui/components/search/search.go b/ui/components/search/search.go index d18184c4..b2c86274 100644 --- a/ui/components/search/search.go +++ b/ui/components/search/search.go @@ -26,7 +26,8 @@ func NewModel(ctx *context.ProgramContext, opts SearchOptions) Model { prompt := fmt.Sprintf(" %s ", opts.Prefix) ti := textinput.New() ti.Placeholder = opts.Placeholder - ti.Width = getInputWidth(ctx, prompt) + ti.PlaceholderStyle = lipgloss.NewStyle().Foreground(ctx.Theme.FaintText) + ti.Width = 0 ti.PromptStyle = ti.PromptStyle.Foreground(ctx.Theme.SecondaryText) ti.Prompt = prompt ti.TextStyle = ti.TextStyle.Faint(true) @@ -80,13 +81,17 @@ func (m *Model) SetValue(val string) { } func (m *Model) UpdateProgramContext(ctx *context.ProgramContext) { - m.textInput.Width = getInputWidth(ctx, m.textInput.Prompt) + m.textInput.Width = m.getInputWidth(ctx) m.textInput.SetValue(m.textInput.Value()) m.textInput.Blur() } -func getInputWidth(ctx *context.ProgramContext, prompt string) int { - return ctx.MainContentWidth - lipgloss.Width(prompt) - 6 +func (m *Model) getInputWidth(ctx *context.ProgramContext) int { + textWidth := 0 + if m.textInput.Value() == "" { + textWidth = lipgloss.Width(m.textInput.Placeholder) + } + return ctx.MainContentWidth - lipgloss.Width(m.textInput.Prompt) - textWidth - 6 } func (m Model) Value() string {