Skip to content

Commit

Permalink
harmonize cursors width
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed Jun 5, 2024
1 parent e670371 commit db9acb9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,18 @@ func (s *Select[T]) choicesView() string {
return sb.String()
}

// Harmonize cursors width
selectedCursor := styles.SelectSelector.String()
unselectedCursor := styles.UnselectSelector.String()
cursorWidth := max(lipgloss.Width(selectedCursor), lipgloss.Width(unselectedCursor))
selectedCursor = styles.SelectSelector.Width(cursorWidth).String()
unselectedCursor = styles.UnselectSelector.Width(cursorWidth).String()

for i, option := range s.filteredOptions {
if s.selected == i {
sb.WriteString(styles.SelectSelector.String() + styles.SelectedOption.Render(option.Key))
sb.WriteString(selectedCursor + styles.SelectedOption.Render(option.Key))
} else {
sb.WriteString(styles.UnselectSelector.String() + styles.Option.Render(option.Key))
sb.WriteString(unselectedCursor + styles.Option.Render(option.Key))
}
if i < len(s.options)-1 {
sb.WriteString("\n")
Expand Down

0 comments on commit db9acb9

Please sign in to comment.