Skip to content

Commit

Permalink
fix(branches): search placeholder (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr authored Aug 31, 2024
1 parent 7792112 commit d7e563b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/components/reposection/reposection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
13 changes: 9 additions & 4 deletions ui/components/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d7e563b

Please sign in to comment.