1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Merge pull request #200 from remyabel/feature/esc-quits

Esc will quit when not in popup, fixes #197
This commit is contained in:
Jesse Duffield 2018-08-24 09:16:56 +10:00 committed by GitHub
commit 6c389df57d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 11 deletions

2
Gopkg.lock generated
View File

@ -77,7 +77,7 @@
branch = "master"
name = "github.com/jesseduffield/gocui"
packages = ["."]
revision = "432b7f6215f81ef1aaa1b2d9b69887822923cf79"
revision = "76a959bb4b0df223fd046b96b68f0162dd609e4b"
[[projects]]
name = "github.com/kevinburke/ssh_config"

View File

@ -16,6 +16,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error {
bindings := []Binding{
{ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.quit},
{ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.quit},
{ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.quit},
{ViewName: "", Key: gocui.KeyPgup, Modifier: gocui.ModNone, Handler: gui.scrollUpMain},
{ViewName: "", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownMain},
{ViewName: "", Key: gocui.KeyCtrlU, Modifier: gocui.ModNone, Handler: gui.scrollUpMain},

View File

@ -653,17 +653,31 @@ func (g *Gui) onKey(ev *termbox.Event) error {
// execKeybindings executes the keybinding handlers that match the passed view
// and event. The value of matched is true if there is a match and no errors.
func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) {
matched = false
var globalKb *keybinding
for _, kb := range g.keybindings {
if kb.handler == nil {
continue
}
if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) {
if err := kb.handler(g, v); err != nil {
return false, err
}
matched = true
if !kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) {
continue
}
if kb.matchView(v) {
return g.execKeybinding(v, kb)
}
if kb.viewName == "" {
globalKb = kb
}
}
return matched, nil
if globalKb != nil {
return g.execKeybinding(v, globalKb)
}
return false, nil
}
// execKeybinding executes a given keybinding
func (g *Gui) execKeybinding(v *View, kb *keybinding) (bool, error) {
if err := kb.handler(g, v); err != nil {
return false, err
}
return true, nil
}

View File

@ -38,9 +38,6 @@ func (kb *keybinding) matchView(v *View) bool {
if v.Editable == true && kb.ch != 0 {
return false
}
if kb.viewName == "" {
return true
}
return v != nil && kb.viewName == v.name
}