Merge branch 'feat/taskedit' into feat/time
This commit is contained in:
@ -637,6 +637,11 @@ func (m *MultiSelect) GetValue() any {
|
||||
return *m.value
|
||||
}
|
||||
|
||||
// IsFiltering returns true if the multi-select is currently filtering.
|
||||
func (m *MultiSelect) IsFiltering() bool {
|
||||
return m.filtering
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
|
||||
@ -37,6 +37,7 @@ type Picker struct {
|
||||
title string
|
||||
filterByDefault bool
|
||||
baseItems []list.Item
|
||||
focused bool
|
||||
}
|
||||
|
||||
type PickerOption func(*Picker)
|
||||
@ -53,6 +54,24 @@ func WithOnCreate(onCreate func(string) tea.Cmd) PickerOption {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Picker) Focus() tea.Cmd {
|
||||
p.focused = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Picker) Blur() tea.Cmd {
|
||||
p.focused = false
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Picker) GetValue() string {
|
||||
item := p.list.SelectedItem()
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
return item.FilterValue()
|
||||
}
|
||||
|
||||
func New(
|
||||
c *common.Common,
|
||||
title string,
|
||||
@ -82,6 +101,7 @@ func New(
|
||||
itemProvider: itemProvider,
|
||||
onSelect: onSelect,
|
||||
title: title,
|
||||
focused: true,
|
||||
}
|
||||
|
||||
if c.TW.GetConfig().Get("uda.tasksquire.picker.filter_by_default") == "yes" {
|
||||
@ -92,6 +112,14 @@ func New(
|
||||
opt(p)
|
||||
}
|
||||
|
||||
if p.filterByDefault {
|
||||
// Manually trigger filter mode on the list so it doesn't require a global key press
|
||||
var cmd tea.Cmd
|
||||
p.list, cmd = p.list.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'i'}})
|
||||
// We can ignore the command here as it's likely just for blinking, which will happen on Init anyway
|
||||
_ = cmd
|
||||
}
|
||||
|
||||
p.Refresh()
|
||||
|
||||
return p
|
||||
@ -134,27 +162,26 @@ func (p *Picker) SetSize(width, height int) {
|
||||
}
|
||||
|
||||
func (p *Picker) Init() tea.Cmd {
|
||||
if p.filterByDefault {
|
||||
return func() tea.Msg {
|
||||
return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'i'}}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Picker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if !p.focused {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
// If filtering, let the list handle keys (including Enter to stop filtering)
|
||||
if p.list.FilterState() == list.Filtering {
|
||||
if key.Matches(msg, p.common.Keymap.Ok) {
|
||||
items := p.list.VisibleItems()
|
||||
if len(items) == 1 {
|
||||
return p, p.handleSelect(items[0])
|
||||
}
|
||||
}
|
||||
// if key.Matches(msg, p.common.Keymap.Ok) {
|
||||
// items := p.list.VisibleItems()
|
||||
// if len(items) == 1 {
|
||||
// return p, p.handleSelect(items[0])
|
||||
// }
|
||||
// }
|
||||
break // Pass to list.Update
|
||||
}
|
||||
|
||||
@ -189,7 +216,12 @@ func (p *Picker) handleSelect(item list.Item) tea.Cmd {
|
||||
}
|
||||
|
||||
func (p *Picker) View() string {
|
||||
title := p.common.Styles.Form.Focused.Title.Render(p.title)
|
||||
var title string
|
||||
if p.focused {
|
||||
title = p.common.Styles.Form.Focused.Title.Render(p.title)
|
||||
} else {
|
||||
title = p.common.Styles.Form.Blurred.Title.Render(p.title)
|
||||
}
|
||||
return lipgloss.JoinVertical(lipgloss.Left, title, p.list.View())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user