From df99ba1899207f6524184f747086c2319baf5d6d Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Mon, 7 Sep 2020 17:38:14 -0400 Subject: [PATCH] I broke the ability to enter j and k in the display filter ... because they were registered as up/down motion keys --- utils.go | 6 ++++++ widgets/filter/filter.go | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/utils.go b/utils.go index dde0039..182eab3 100644 --- a/utils.go +++ b/utils.go @@ -28,6 +28,7 @@ import ( "syscall" "text/template" "time" + "unicode" "github.com/adam-hanna/arrayOperations" "github.com/blang/semver" @@ -36,6 +37,7 @@ import ( "github.com/gcla/gowid/vim" "github.com/gcla/termshark/v2/system" "github.com/gcla/termshark/v2/widgets/resizable" + "github.com/gdamore/tcell" "github.com/mattn/go-isatty" "github.com/pkg/errors" "github.com/shibukawa/configdir" @@ -380,6 +382,10 @@ func TailCommand() []string { return ConfStringSlice("main.tail-command", def) } +func KeyPressIsPrintable(key gowid.IKey) bool { + return unicode.IsPrint(key.Rune()) && key.Modifiers() & ^tcell.ModShift == 0 +} + type KeyMapping struct { From vim.KeyPress To vim.KeySequence diff --git a/widgets/filter/filter.go b/widgets/filter/filter.go index 7ba6594..ca85e51 100644 --- a/widgets/filter/filter.go +++ b/widgets/filter/filter.go @@ -114,10 +114,14 @@ func New(opt Options) *Widget { ign := make([]gowid.IKey, 0, len(vim.AllDownKeys)+len(vim.AllUpKeys)) for _, k := range vim.AllDownKeys { - ign = append(ign, k) + if !termshark.KeyPressIsPrintable(k) { + ign = append(ign, k) + } } for _, k := range vim.AllUpKeys { - ign = append(ign, k) + if !termshark.KeyPressIsPrintable(k) { + ign = append(ign, k) + } } drop := menu.New("filter", menuListBox2, gowid.RenderWithUnits{U: opt.MaxCompletions + 2}, @@ -633,7 +637,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 || vim.KeyIn(evk, vim.AllDownKeys) { + if evk.Key() == tcell.KeyTAB || (vim.KeyIn(evk, vim.AllDownKeys) && !termshark.KeyPressIsPrintable(evk)) { return false } } @@ -656,7 +660,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 vim.KeyIn(ev, vim.AllDownKeys) { + if vim.KeyIn(ev, vim.AllDownKeys) && !termshark.KeyPressIsPrintable(ev) { w.active = true return true } else { @@ -666,7 +670,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 vim.KeyIn(ev, vim.AllUpKeys) { + if vim.KeyIn(ev, vim.AllUpKeys) && !termshark.KeyPressIsPrintable(ev) { w.active = false return true } else {