From 26db5255e4fa899f7f5baa667fad084bc6ada51a Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 2 Jan 2021 17:04:29 -0500 Subject: [PATCH] Change default behavior of the Escape key Prior to this change, the escape key set focus on the button that opens the menu, and then also opened the menu. Now that there's a minibuffer/cmdline, I find this Escape behavior confusing. For example, if you're focused in the display filter and you want to run a minibuffer command, it's instinctive to hit Escape to "leave" the focus of the filter and then ":" to open the command-line. But Escape will open the menu; so then you need to hit Escape to close it again before ":" for the command-line. Now, Escape will put focus on the menu button, but not open the menu. Just hit Enter to open it. Putting focus on the Menu button, in particular takes focus away from the filter widget, so the command-line will still be ":" keypress away. --- CHANGELOG.md | 2 ++ ui/ui.go | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3ffaf..952df85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ are loaded from `~/.config/termshark/themes/` or from a small cache built-in to termshark. A new minibuffer command `theme` can be used to change theme; `no-theme` turns off theming. +- The Escape key no longer opens the main menu. Instead it puts focus on the menu button. Hit Enter to open. + This is more intuitive with the presence of ":" to open the minibuffer. ### Changed diff --git a/ui/ui.go b/ui/ui.go index dd18ace..c308d02 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -1048,6 +1048,11 @@ func lastLineMode(app gowid.IApp) { return nil })) + MiniBuffer.Register("menu", minibufferFn(func(gowid.IApp, ...string) error { + openGeneralMenu(app) + return nil + })) + MiniBuffer.Register("clear-packets", minibufferFn(func(gowid.IApp, ...string) error { reallyClear(app) return nil @@ -1747,10 +1752,23 @@ func mainKeyPress(evk *tcell.EventKey, app gowid.IApp) bool { return handled } +func focusOnMenuButton(app gowid.IApp) { + gowid.SetFocusPath(mainview, menuPathMain, app) + gowid.SetFocusPath(altview1, menuPathAlt, app) + gowid.SetFocusPath(altview2, menuPathAlt, app) + gowid.SetFocusPath(viewOnlyPacketList, menuPathMax, app) + gowid.SetFocusPath(viewOnlyPacketStructure, menuPathMax, app) + gowid.SetFocusPath(viewOnlyPacketHex, menuPathMax, app) +} + +func openGeneralMenu(app gowid.IApp) { + focusOnMenuButton(app) + generalMenu.Open(openMenuSite, app) +} + // Keys for the whole app, applicable whichever view is frontmost func appKeyPress(evk *tcell.EventKey, app gowid.IApp) bool { handled := true - // gcla later todo - check for rune! isrune := evk.Key() == tcell.KeyRune if evk.Key() == tcell.KeyCtrlC { @@ -1762,14 +1780,7 @@ func appKeyPress(evk *tcell.EventKey, app gowid.IApp) bool { } else if isrune && evk.Rune() == ':' { lastLineMode(app) } else if evk.Key() == tcell.KeyEscape { - gowid.SetFocusPath(mainview, menuPathMain, app) - gowid.SetFocusPath(altview1, menuPathAlt, app) - gowid.SetFocusPath(altview2, menuPathAlt, app) - gowid.SetFocusPath(viewOnlyPacketList, menuPathMax, app) - gowid.SetFocusPath(viewOnlyPacketStructure, menuPathMax, app) - gowid.SetFocusPath(viewOnlyPacketHex, menuPathMax, app) - - generalMenu.Open(openMenuSite, app) + focusOnMenuButton(app) } else if isrune && evk.Rune() == '?' { OpenTemplatedDialog(appView, "UIHelp", app) } else if isrune && evk.Rune() == 'Z' && keyState.PartialZCmd {