diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index ecc14f6a..084ccd62 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -540,7 +540,10 @@ func (h *BufPane) Bindings() *KeyTree { } // DoKeyEvent executes a key event by finding the action it is bound -// to and executing it (possibly multiple times for multiple cursors) +// to and executing it (possibly multiple times for multiple cursors). +// Returns true if the action was executed OR if there are more keys +// remaining to process before executing an action (if this is a key +// sequence event). Returns false if no action found. func (h *BufPane) DoKeyEvent(e Event) bool { binds := h.Bindings() action, more := binds.NextEvent(e, nil) diff --git a/internal/action/infopane.go b/internal/action/infopane.go index a9baf431..d3f30fd4 100644 --- a/internal/action/infopane.go +++ b/internal/action/infopane.go @@ -95,12 +95,14 @@ func (h *InfoPane) HandleEvent(event tcell.Event) { done := h.DoKeyEvent(ke) hasYN := h.HasYN if e.Key() == tcell.KeyRune && hasYN { - if (e.Rune() == 'y' || e.Rune() == 'Y') && hasYN { - h.YNResp = true - h.DonePrompt(false) - } else if (e.Rune() == 'n' || e.Rune() == 'N') && hasYN { - h.YNResp = false + y := e.Rune() == 'y' || e.Rune() == 'Y' + n := e.Rune() == 'n' || e.Rune() == 'N' + if y || n { + h.YNResp = y h.DonePrompt(false) + + InfoBindings.ResetEvents() + InfoBufBindings.ResetEvents() } } if e.Key() == tcell.KeyRune && !done && !hasYN { @@ -124,7 +126,10 @@ func (h *InfoPane) HandleEvent(event tcell.Event) { } } -// DoKeyEvent executes a key event for the command bar, doing any overridden actions +// DoKeyEvent executes a key event for the command bar, doing any overridden actions. +// Returns true if the action was executed OR if there are more keys remaining +// to process before executing an action (if this is a key sequence event). +// Returns false if no action found. func (h *InfoPane) DoKeyEvent(e KeyEvent) bool { action, more := InfoBindings.NextEvent(e, nil) if action != nil && !more { @@ -138,11 +143,25 @@ func (h *InfoPane) DoKeyEvent(e KeyEvent) bool { } if !more { + // If no infopane action found, try to find a bufpane action. + // + // TODO: this is buggy. For example, if the command bar has the following + // two bindings: + // + // "": "HistoryUp", + // "": "Paste", + // + // the 2nd binding (with a bufpane action) doesn't work, since + // has been already consumed by the 1st binding (with an infopane action). + // + // We should either iterate both InfoBindings and InfoBufBindings keytrees + // together, or just use the same keytree for both infopane and bufpane + // bindings. action, more = InfoBufBindings.NextEvent(e, nil) if action != nil && !more { - done := action(h.BufPane) + action(h.BufPane) InfoBufBindings.ResetEvents() - return done + return true } else if action == nil && !more { InfoBufBindings.ResetEvents() }