From e670371729a57e063d7afbdd41ea09561d0fe195 Mon Sep 17 00:00:00 2001 From: Florian Rey Date: Wed, 29 May 2024 19:54:51 +0200 Subject: [PATCH 1/2] feat: unselect selector --- field_select.go | 5 ++--- theme.go | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/field_select.go b/field_select.go index 2202ccae..87b84eaf 100644 --- a/field_select.go +++ b/field_select.go @@ -367,7 +367,6 @@ func (s *Select[T]) descriptionView() string { func (s *Select[T]) choicesView() string { var ( styles = s.activeStyles() - c = styles.SelectSelector.String() sb strings.Builder ) @@ -384,9 +383,9 @@ func (s *Select[T]) choicesView() string { for i, option := range s.filteredOptions { if s.selected == i { - sb.WriteString(c + styles.SelectedOption.Render(option.Key)) + sb.WriteString(styles.SelectSelector.String() + styles.SelectedOption.Render(option.Key)) } else { - sb.WriteString(strings.Repeat(" ", lipgloss.Width(c)) + styles.Option.Render(option.Key)) + sb.WriteString(styles.UnselectSelector.String() + styles.Option.Render(option.Key)) } if i < len(s.options)-1 { sb.WriteString("\n") diff --git a/theme.go b/theme.go index 32982a1b..8c714c98 100644 --- a/theme.go +++ b/theme.go @@ -26,10 +26,11 @@ type FieldStyles struct { ErrorMessage lipgloss.Style // Select styles. - SelectSelector lipgloss.Style // Selection indicator - Option lipgloss.Style // Select options - NextIndicator lipgloss.Style - PrevIndicator lipgloss.Style + SelectSelector lipgloss.Style // Selection indicator + UnselectSelector lipgloss.Style + Option lipgloss.Style // Select options + NextIndicator lipgloss.Style + PrevIndicator lipgloss.Style // FilePicker styles. Directory lipgloss.Style @@ -86,6 +87,7 @@ func ThemeBase() *Theme { t.Focused.ErrorIndicator = lipgloss.NewStyle().SetString(" *") t.Focused.ErrorMessage = lipgloss.NewStyle().SetString(" *") t.Focused.SelectSelector = lipgloss.NewStyle().SetString("> ") + t.Focused.UnselectSelector = lipgloss.NewStyle().SetString(" ") t.Focused.NextIndicator = lipgloss.NewStyle().MarginLeft(1).SetString("→") t.Focused.PrevIndicator = lipgloss.NewStyle().MarginRight(1).SetString("←") t.Focused.MultiSelectSelector = lipgloss.NewStyle().SetString("> ") From db9acb945311b15d32606981ed0f0cbcc645ddb3 Mon Sep 17 00:00:00 2001 From: Florian Rey Date: Wed, 5 Jun 2024 10:46:32 +0200 Subject: [PATCH 2/2] harmonize cursors width --- field_select.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/field_select.go b/field_select.go index 87b84eaf..e7ea3bc2 100644 --- a/field_select.go +++ b/field_select.go @@ -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")