Skip to content

Commit ff5b147

Browse files
authored
Merge pull request zyedidia#3267 from dmaluka/dokeyevent-improvements
Small fixes and improvements for InfoPane's key event handling
2 parents 3f810c2 + 8632b82 commit ff5b147

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

internal/action/bufpane.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ func (h *BufPane) Bindings() *KeyTree {
540540
}
541541

542542
// DoKeyEvent executes a key event by finding the action it is bound
543-
// to and executing it (possibly multiple times for multiple cursors)
543+
// to and executing it (possibly multiple times for multiple cursors).
544+
// Returns true if the action was executed OR if there are more keys
545+
// remaining to process before executing an action (if this is a key
546+
// sequence event). Returns false if no action found.
544547
func (h *BufPane) DoKeyEvent(e Event) bool {
545548
binds := h.Bindings()
546549
action, more := binds.NextEvent(e, nil)

internal/action/infopane.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ func (h *InfoPane) HandleEvent(event tcell.Event) {
9595
done := h.DoKeyEvent(ke)
9696
hasYN := h.HasYN
9797
if e.Key() == tcell.KeyRune && hasYN {
98-
if (e.Rune() == 'y' || e.Rune() == 'Y') && hasYN {
99-
h.YNResp = true
100-
h.DonePrompt(false)
101-
} else if (e.Rune() == 'n' || e.Rune() == 'N') && hasYN {
102-
h.YNResp = false
98+
y := e.Rune() == 'y' || e.Rune() == 'Y'
99+
n := e.Rune() == 'n' || e.Rune() == 'N'
100+
if y || n {
101+
h.YNResp = y
103102
h.DonePrompt(false)
103+
104+
InfoBindings.ResetEvents()
105+
InfoBufBindings.ResetEvents()
104106
}
105107
}
106108
if e.Key() == tcell.KeyRune && !done && !hasYN {
@@ -124,7 +126,10 @@ func (h *InfoPane) HandleEvent(event tcell.Event) {
124126
}
125127
}
126128

127-
// DoKeyEvent executes a key event for the command bar, doing any overridden actions
129+
// DoKeyEvent executes a key event for the command bar, doing any overridden actions.
130+
// Returns true if the action was executed OR if there are more keys remaining
131+
// to process before executing an action (if this is a key sequence event).
132+
// Returns false if no action found.
128133
func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
129134
action, more := InfoBindings.NextEvent(e, nil)
130135
if action != nil && !more {
@@ -138,11 +143,25 @@ func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
138143
}
139144

140145
if !more {
146+
// If no infopane action found, try to find a bufpane action.
147+
//
148+
// TODO: this is buggy. For example, if the command bar has the following
149+
// two bindings:
150+
//
151+
// "<Ctrl-x><Ctrl-p>": "HistoryUp",
152+
// "<Ctrl-x><Ctrl-v>": "Paste",
153+
//
154+
// the 2nd binding (with a bufpane action) doesn't work, since <Ctrl-x>
155+
// has been already consumed by the 1st binding (with an infopane action).
156+
//
157+
// We should either iterate both InfoBindings and InfoBufBindings keytrees
158+
// together, or just use the same keytree for both infopane and bufpane
159+
// bindings.
141160
action, more = InfoBufBindings.NextEvent(e, nil)
142161
if action != nil && !more {
143-
done := action(h.BufPane)
162+
action(h.BufPane)
144163
InfoBufBindings.ResetEvents()
145-
return done
164+
return true
146165
} else if action == nil && !more {
147166
InfoBufBindings.ResetEvents()
148167
}

0 commit comments

Comments
 (0)