Skip to content

Commit

Permalink
pkg/cli: In the CodeArea widget, do not consult key binding when past…
Browse files Browse the repository at this point in the history
…ing.

This fixes #890.
  • Loading branch information
xiaq committed Jan 1, 2020
1 parent a2141c3 commit 4df6178
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/cli/codearea.go
Expand Up @@ -153,10 +153,6 @@ func (w *codeArea) Render(width, height int) *term.Buffer {
// Handle handles KeyEvent's of non-function keys, as well as PasteSetting
// events.
func (w *codeArea) Handle(event term.Event) bool {
if w.OverlayHandler.Handle(event) {
return true
}

switch event := event.(type) {
case term.PasteSetting:
return w.handlePasteSetting(bool(event))
Expand Down Expand Up @@ -211,6 +207,9 @@ func (w *codeArea) handleKeyEvent(key ui.Key) bool {
}
return true
}
if w.OverlayHandler.Handle(term.KeyEvent(key)) {
return true
}
// We only implement essential keybindings here. Other keybindings can be
// added via handler overlays.
switch key {
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/codearea_test.go
Expand Up @@ -303,6 +303,16 @@ var codeAreaHandleTests = []HandleTest{
Events: []term.Event{term.K('a')},
WantNewState: CodeAreaState{Buffer: CodeBuffer{Content: "b", Dot: 1}},
},
{
// Regression test for #890.
Name: "overlay handler does not apply when pasting",
Given: codeAreaWithOverlay(CodeAreaSpec{}, func(w *codeArea) Handler {
return MapHandler{term.K('\n'): func() {}}
}),
Events: []term.Event{
term.PasteSetting(true), term.K('\n'), term.PasteSetting(false)},
WantNewState: CodeAreaState{Buffer: CodeBuffer{Content: "\n", Dot: 1}},
},
}

func TestCodeArea_Handle(t *testing.T) {
Expand Down

0 comments on commit 4df6178

Please sign in to comment.