Preview filter while browsing an open dropdown; Esc closes only the list

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 20:42:53 +02:00
co-authored by Claude Sonnet 5.5
parent 6b780242c9
commit ac1c2ebce2
6 changed files with 146 additions and 16 deletions
+18 -9
View File
@@ -131,14 +131,20 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, set func(attrFi
AddDropDown(lAudio, withAny(audioOptions), indexOf(audioOptions, cur.audio), nil).
AddDropDown(lLang, withAny(languages), indexOf(languages, cur.lang), nil)
pick := func(label string, options []string) string {
i := selected(form, label)
if i <= 0 {
return ""
// filterWith reads the dialog; the entry at index in dropdown over (if
// any) stands in for that dropdown's committed choice.
filterWith := func(over *tview.DropDown, index int) attrFilter {
pick := func(label string, options []string) string {
dd := form.GetFormItemByLabel(label).(*tview.DropDown)
i, _ := dd.GetCurrentOption()
if dd == over {
i = index
}
if i <= 0 {
return ""
}
return options[i-1]
}
return options[i-1]
}
current := func() attrFilter {
return attrFilter{
res: pick(lRes, resOptions),
codec: pick(lCodec, codecOptions),
@@ -147,6 +153,7 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, set func(attrFi
lang: pick(lLang, languages),
}
}
current := func() attrFilter { return filterWith(nil, 0) }
for _, label := range []string{lRes, lCodec, lHDR, lAudio, lLang} {
form.GetFormItemByLabel(label).(*tview.DropDown).SetSelectedFunc(func(string, int) { set(current()) })
}
@@ -161,8 +168,10 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, set func(attrFi
set(attrFilter{})
})
form.AddButton("Cancel", cancel)
form.SetCancelFunc(cancel)
arrowNavigation(form)
arrowNavigation(form, cancel, &browseHooks{
browse: func(dd *tview.DropDown, index int) { set(filterWith(dd, index)) },
abort: func() { set(current()) }, // list closed without choosing: back to the committed value
})
form.SetBorder(true).SetTitle(" Filter by properties ")
a.openSidePanel(form, 40, 17, "↑↓ move · ←→ change (applies live) · Enter apply · Esc cancel")
}