From 23bd76f11d3534274d019737c27f19c280d0203d Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Mon, 7 Sep 2020 16:08:08 -0400 Subject: [PATCH] Have the display filter respect all typical up/down keys Ctrl-n and Ctrl-p will move up and down the list, but special treatment is needed to move from the filter edit box to the first list entry; here I am now handling Ctrl-n in the same was as down arrow, and then when at the top of the list, Ctrl-p the same way as up arrow. --- widgets/filter/filter.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/widgets/filter/filter.go b/widgets/filter/filter.go index c37f829..7ba6594 100644 --- a/widgets/filter/filter.go +++ b/widgets/filter/filter.go @@ -19,6 +19,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/gowid/gwutil" + "github.com/gcla/gowid/vim" "github.com/gcla/gowid/widgets/button" "github.com/gcla/gowid/widgets/cellmod" "github.com/gcla/gowid/widgets/columns" @@ -111,15 +112,20 @@ func New(opt Options) *Widget { gowid.MakePaletteRef("filter-menu"), ) + ign := make([]gowid.IKey, 0, len(vim.AllDownKeys)+len(vim.AllUpKeys)) + for _, k := range vim.AllDownKeys { + ign = append(ign, k) + } + for _, k := range vim.AllUpKeys { + ign = append(ign, k) + } + drop := menu.New("filter", menuListBox2, gowid.RenderWithUnits{U: opt.MaxCompletions + 2}, menu.Options{ IgnoreKeysProvided: true, - IgnoreKeys: []gowid.IKey{ - gowid.MakeKeyExt(tcell.KeyUp), - gowid.MakeKeyExt(tcell.KeyDown), - }, - CloseKeysProvided: true, - CloseKeys: []gowid.IKey{}, + IgnoreKeys: ign, + CloseKeysProvided: true, + CloseKeys: []gowid.IKey{}, }, ) @@ -627,7 +633,7 @@ func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid. // it go orange briefly, which is unpleasant. func (w *Widget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool { if evk, ok := ev.(*tcell.EventKey); ok { - if evk.Key() == tcell.KeyTAB || evk.Key() == tcell.KeyDown { + if evk.Key() == tcell.KeyTAB || vim.KeyIn(evk, vim.AllDownKeys) { return false } } @@ -650,7 +656,7 @@ type activatorWidget struct { func (w *activatorWidget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool { if ev, ok := ev.(*tcell.EventKey); ok && !w.active { - if ev.Key() == tcell.KeyDown { + if vim.KeyIn(ev, vim.AllDownKeys) { w.active = true return true } else { @@ -660,7 +666,7 @@ func (w *activatorWidget) UserInput(ev interface{}, size gowid.IRenderSize, focu res := w.IWidget.UserInput(ev, size, focus, app) if !res { if ev, ok := ev.(*tcell.EventKey); ok && w.active { - if ev.Key() == tcell.KeyUp { + if vim.KeyIn(ev, vim.AllUpKeys) { w.active = false return true } else {