Skip to content

Commit

Permalink
I broke the ability to enter j and k in the display filter
Browse files Browse the repository at this point in the history
... because they were registered as up/down motion keys
  • Loading branch information
gcla committed Sep 7, 2020
1 parent 23bd76f commit df99ba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"syscall"
"text/template"
"time"
"unicode"

"github.com/adam-hanna/arrayOperations"
"github.com/blang/semver"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions widgets/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit df99ba1

Please sign in to comment.