Decouple escaping from quitting

When a user is not entering text into a prompt, the 'q' key should immediately
quit the application. On the other hand, the 'esc' key should cancel/close/go-back
to the previous context.

If we're at the surface level (nothing to cancel/close) and the user hits the
escape key, the default behaviour is to close the app, however we now have a
`quitOnTopLevelReturn` config key to override this.

I actually think from the beginning we should have made this config option
default to false rather than true which is the default this PR gives it,
but I don't want to anger too many people familiar with the existing behaviour.
This commit is contained in:
Jesse Duffield 2020-07-18 19:41:13 +10:00
parent 0e65db10d8
commit 845c80721f
11 changed files with 34 additions and 16 deletions

View file

@ -50,6 +50,8 @@ Default path for the config file:
days: 14 # how often an update is checked for days: 14 # how often an update is checked for
reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined' reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined'
confirmOnQuit: false confirmOnQuit: false
# determines whether hitting 'esc' will quit the application when there is nothing to cancel/close
quitOnTopLevelReturn: true
keybinding: keybinding:
universal: universal:
quit: 'q' quit: 'q'

View file

@ -16,6 +16,8 @@
<kbd>+</kbd>: next screen mode (normal/half/fullscreen) <kbd>+</kbd>: next screen mode (normal/half/fullscreen)
<kbd>_</kbd>: prev screen mode <kbd>_</kbd>: prev screen mode
<kbd>:</kbd>: execute custom command <kbd>:</kbd>: execute custom command
<kbd>|</kbd>: view scoping options
<kbd>ctrl+e</kbd>: open diff menu
</pre> </pre>
## Branches Panel ## Branches Panel
@ -40,6 +42,7 @@
<kbd>f</kbd>: fast-forward this branch from its upstream <kbd>f</kbd>: fast-forward this branch from its upstream
<kbd>g</kbd>: view reset options <kbd>g</kbd>: view reset options
<kbd>R</kbd>: rename branch <kbd>R</kbd>: rename branch
<kbd>ctrl+o</kbd>: copy branch name to clipboard
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top
@ -53,6 +56,7 @@
<kbd>esc</kbd>: return to remotes list <kbd>esc</kbd>: return to remotes list
<kbd>g</kbd>: view reset options <kbd>g</kbd>: view reset options
<kbd>space</kbd>: checkout <kbd>space</kbd>: checkout
<kbd>n</kbd>: new branch
<kbd>M</kbd>: merge into currently checked out branch <kbd>M</kbd>: merge into currently checked out branch
<kbd>d</kbd>: delete branch <kbd>d</kbd>: delete branch
<kbd>r</kbd>: rebase checked-out branch onto this branch <kbd>r</kbd>: rebase checked-out branch onto this branch
@ -134,11 +138,11 @@
<kbd>p</kbd>: pick commit (when mid-rebase) <kbd>p</kbd>: pick commit (when mid-rebase)
<kbd>t</kbd>: revert commit <kbd>t</kbd>: revert commit
<kbd>c</kbd>: copy commit (cherry-pick) <kbd>c</kbd>: copy commit (cherry-pick)
<kbd>ctrl+o</kbd>: copy commit SHA to clipboard
<kbd>C</kbd>: copy commit range (cherry-pick) <kbd>C</kbd>: copy commit range (cherry-pick)
<kbd>v</kbd>: paste commits (cherry-pick) <kbd>v</kbd>: paste commits (cherry-pick)
<kbd>enter</kbd>: view commit's files <kbd>enter</kbd>: view commit's files
<kbd>space</kbd>: checkout commit <kbd>space</kbd>: checkout commit
<kbd>i</kbd>: select commit to diff with another commit
<kbd>T</kbd>: tag commit <kbd>T</kbd>: tag commit
<kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection <kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
@ -246,7 +250,6 @@
<pre> <pre>
<kbd>esc</kbd>: close menu <kbd>esc</kbd>: close menu
<kbd>q</kbd>: close menu
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top

View file

@ -16,6 +16,8 @@
<kbd>+</kbd>: next screen mode (normal/half/fullscreen) <kbd>+</kbd>: next screen mode (normal/half/fullscreen)
<kbd>_</kbd>: prev screen mode <kbd>_</kbd>: prev screen mode
<kbd>:</kbd>: voor aangepast commando uit <kbd>:</kbd>: voor aangepast commando uit
<kbd>|</kbd>: view scoping options
<kbd>ctrl+e</kbd>: open diff menu
</pre> </pre>
## Branches Panel ## Branches Panel
@ -40,6 +42,7 @@
<kbd>f</kbd>: fast-forward this branch from its upstream <kbd>f</kbd>: fast-forward this branch from its upstream
<kbd>g</kbd>: bekijk reset opties <kbd>g</kbd>: bekijk reset opties
<kbd>R</kbd>: rename branch <kbd>R</kbd>: rename branch
<kbd>ctrl+o</kbd>: copy branch name to clipboard
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top
@ -53,6 +56,7 @@
<kbd>esc</kbd>: return to remotes list <kbd>esc</kbd>: return to remotes list
<kbd>g</kbd>: bekijk reset opties <kbd>g</kbd>: bekijk reset opties
<kbd>space</kbd>: uitchecken <kbd>space</kbd>: uitchecken
<kbd>n</kbd>: nieuwe branch
<kbd>M</kbd>: merge in met huidige checked out branch <kbd>M</kbd>: merge in met huidige checked out branch
<kbd>d</kbd>: verwijder branch <kbd>d</kbd>: verwijder branch
<kbd>r</kbd>: rebase branch <kbd>r</kbd>: rebase branch
@ -134,11 +138,11 @@
<kbd>p</kbd>: pick commit (when mid-rebase) <kbd>p</kbd>: pick commit (when mid-rebase)
<kbd>t</kbd>: commit omgedaan maken <kbd>t</kbd>: commit omgedaan maken
<kbd>c</kbd>: kopiëer commit (cherry-pick) <kbd>c</kbd>: kopiëer commit (cherry-pick)
<kbd>ctrl+o</kbd>: copy commit SHA to clipboard
<kbd>C</kbd>: kopiëer commit reeks (cherry-pick) <kbd>C</kbd>: kopiëer commit reeks (cherry-pick)
<kbd>v</kbd>: plak commits (cherry-pick) <kbd>v</kbd>: plak commits (cherry-pick)
<kbd>enter</kbd>: bekijk gecommite bestanden <kbd>enter</kbd>: bekijk gecommite bestanden
<kbd>space</kbd>: checkout commit <kbd>space</kbd>: checkout commit
<kbd>i</kbd>: select commit to diff with another commit
<kbd>T</kbd>: tag commit <kbd>T</kbd>: tag commit
<kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection <kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
@ -246,7 +250,6 @@
<pre> <pre>
<kbd>esc</kbd>: close menu <kbd>esc</kbd>: close menu
<kbd>q</kbd>: close menu
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top

View file

@ -16,6 +16,8 @@
<kbd>+</kbd>: next screen mode (normal/half/fullscreen) <kbd>+</kbd>: next screen mode (normal/half/fullscreen)
<kbd>_</kbd>: prev screen mode <kbd>_</kbd>: prev screen mode
<kbd>:</kbd>: execute custom command <kbd>:</kbd>: execute custom command
<kbd>|</kbd>: view scoping options
<kbd>ctrl+e</kbd>: open diff menu
</pre> </pre>
## Gałęzie Panel ## Gałęzie Panel
@ -40,6 +42,7 @@
<kbd>f</kbd>: fast-forward this branch from its upstream <kbd>f</kbd>: fast-forward this branch from its upstream
<kbd>g</kbd>: view reset options <kbd>g</kbd>: view reset options
<kbd>R</kbd>: rename branch <kbd>R</kbd>: rename branch
<kbd>ctrl+o</kbd>: copy branch name to clipboard
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top
@ -53,6 +56,7 @@
<kbd>esc</kbd>: return to remotes list <kbd>esc</kbd>: return to remotes list
<kbd>g</kbd>: view reset options <kbd>g</kbd>: view reset options
<kbd>space</kbd>: przełącz <kbd>space</kbd>: przełącz
<kbd>n</kbd>: nowa gałąź
<kbd>M</kbd>: scal do obecnej gałęzi <kbd>M</kbd>: scal do obecnej gałęzi
<kbd>d</kbd>: usuń gałąź <kbd>d</kbd>: usuń gałąź
<kbd>r</kbd>: rebase branch <kbd>r</kbd>: rebase branch
@ -134,11 +138,11 @@
<kbd>p</kbd>: pick commit (when mid-rebase) <kbd>p</kbd>: pick commit (when mid-rebase)
<kbd>t</kbd>: revert commit <kbd>t</kbd>: revert commit
<kbd>c</kbd>: copy commit (cherry-pick) <kbd>c</kbd>: copy commit (cherry-pick)
<kbd>ctrl+o</kbd>: copy commit SHA to clipboard
<kbd>C</kbd>: copy commit range (cherry-pick) <kbd>C</kbd>: copy commit range (cherry-pick)
<kbd>v</kbd>: paste commits (cherry-pick) <kbd>v</kbd>: paste commits (cherry-pick)
<kbd>enter</kbd>: view commit's files <kbd>enter</kbd>: view commit's files
<kbd>space</kbd>: checkout commit <kbd>space</kbd>: checkout commit
<kbd>i</kbd>: select commit to diff with another commit
<kbd>T</kbd>: tag commit <kbd>T</kbd>: tag commit
<kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection <kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
@ -246,7 +250,6 @@
<pre> <pre>
<kbd>esc</kbd>: close menu <kbd>esc</kbd>: close menu
<kbd>q</kbd>: close menu
<kbd>,</kbd>: previous page <kbd>,</kbd>: previous page
<kbd>.</kbd>: next page <kbd>.</kbd>: next page
<kbd><</kbd>: scroll to top <kbd><</kbd>: scroll to top

View file

@ -278,6 +278,7 @@ update:
reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined' reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined'
splashUpdatesIndex: 0 splashUpdatesIndex: 0
confirmOnQuit: false confirmOnQuit: false
quitOnTopLevelReturn: true
keybinding: keybinding:
universal: universal:
quit: 'q' quit: 'q'

View file

@ -217,7 +217,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "", ViewName: "",
Key: gui.getKey("universal.return"), Key: gui.getKey("universal.return"),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleQuit, Handler: gui.handleTopLevelReturn,
}, },
{ {
ViewName: "", ViewName: "",
@ -848,12 +848,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleMenuClose, Handler: gui.handleMenuClose,
Description: gui.Tr.SLocalize("closeMenu"), Description: gui.Tr.SLocalize("closeMenu"),
}, },
{
ViewName: "menu",
Key: gui.getKey("universal.quit"),
Handler: gui.handleMenuClose,
Description: gui.Tr.SLocalize("closeMenu"),
},
{ {
ViewName: "information", ViewName: "information",
Key: gocui.MouseLeft, Key: gocui.MouseLeft,

View file

@ -25,7 +25,7 @@ func (gui *Gui) handleMenuSelect(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) renderMenuOptions() error { func (gui *Gui) renderMenuOptions() error {
optionsMap := map[string]string{ optionsMap := map[string]string{
fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.return"), gui.getKeyDisplay("universal.quit")): gui.Tr.SLocalize("close"), gui.getKeyDisplay("universal.return"): gui.Tr.SLocalize("close"),
fmt.Sprintf("%s %s", gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"), fmt.Sprintf("%s %s", gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"),
gui.getKeyDisplay("universal.select"): gui.Tr.SLocalize("execute"), gui.getKeyDisplay("universal.select"): gui.Tr.SLocalize("execute"),
} }

View file

@ -34,6 +34,14 @@ func (gui *Gui) handleQuit(g *gocui.Gui, v *gocui.View) error {
return gui.quit(v) return gui.quit(v)
} }
func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
return gui.handleQuit(g, v)
}
return nil
}
func (gui *Gui) quit(v *gocui.View) error { func (gui *Gui) quit(v *gocui.View) error {
if gui.State.Updating { if gui.State.Updating {
return gui.createUpdateQuitConfirmation(gui.g, v) return gui.createUpdateQuitConfirmation(gui.g, v)

View file

@ -513,7 +513,8 @@ func (gui *Gui) renderGlobalOptions() error {
return gui.renderOptionsMap(map[string]string{ return gui.renderOptionsMap(map[string]string{
fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.scrollUpMain"), gui.getKeyDisplay("universal.scrollDownMain")): gui.Tr.SLocalize("scroll"), fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.scrollUpMain"), gui.getKeyDisplay("universal.scrollDownMain")): gui.Tr.SLocalize("scroll"),
fmt.Sprintf("%s %s %s %s", gui.getKeyDisplay("universal.prevBlock"), gui.getKeyDisplay("universal.nextBlock"), gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"), fmt.Sprintf("%s %s %s %s", gui.getKeyDisplay("universal.prevBlock"), gui.getKeyDisplay("universal.nextBlock"), gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"),
fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.return"), gui.getKeyDisplay("universal.quit")): gui.Tr.SLocalize("close"), gui.getKeyDisplay("universal.return"): gui.Tr.SLocalize("cancel"),
gui.getKeyDisplay("universal.quit"): gui.Tr.SLocalize("quit"),
gui.getKeyDisplay("universal.optionMenu"): gui.Tr.SLocalize("menu"), gui.getKeyDisplay("universal.optionMenu"): gui.Tr.SLocalize("menu"),
"1-5": gui.Tr.SLocalize("jump"), "1-5": gui.Tr.SLocalize("jump"),
}) })

View file

@ -249,6 +249,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "close", ID: "close",
Other: "close", Other: "close",
}, &i18n.Message{
ID: "quit",
Other: "quit",
}, &i18n.Message{ }, &i18n.Message{
ID: "SureResetThisCommit", ID: "SureResetThisCommit",
Other: "Are you sure you want to reset to this commit?", Other: "Are you sure you want to reset to this commit?",

View file

@ -31,7 +31,7 @@ func main() {
for _, lang := range langs { for _, lang := range langs {
os.Setenv("LC_ALL", lang) os.Setenv("LC_ALL", lang)
mApp, _ := app.NewApp(mConfig) mApp, _ := app.NewApp(mConfig, "")
file, err := os.Create(getProjectRoot() + "/docs/keybindings/Keybindings_" + lang + ".md") file, err := os.Create(getProjectRoot() + "/docs/keybindings/Keybindings_" + lang + ".md")
if err != nil { if err != nil {
panic(err) panic(err)