Merge pull request #3267 from dmaluka/dokeyevent-improvements
Small fixes and improvements for InfoPane's key event handling
This commit is contained in:
commit
ff5b147639
2 changed files with 31 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
//
|
||||
// "<Ctrl-x><Ctrl-p>": "HistoryUp",
|
||||
// "<Ctrl-x><Ctrl-v>": "Paste",
|
||||
//
|
||||
// the 2nd binding (with a bufpane action) doesn't work, since <Ctrl-x>
|
||||
// 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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue