Skip to content

Commit

Permalink
Change default behavior of the Escape key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gcla committed Jan 2, 2021
1 parent 3cd954b commit 26db525
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 20 additions & 9 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 26db525

Please sign in to comment.