diff --git a/tui/keys.go b/tui/keys.go index 76629dcbf..18e49e867 100644 --- a/tui/keys.go +++ b/tui/keys.go @@ -33,8 +33,11 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { return nil } - if ui.pages.HasPage("confirm") || - ui.pages.HasPage("progress") || + if ui.pages.HasPage("confirm") { + return ui.handleConfirmation(key) + } + + if ui.pages.HasPage("progress") || ui.pages.HasPage("deleting") || ui.pages.HasPage("emptying") { return key @@ -83,6 +86,16 @@ func (ui *UI) handleClosingModals(key *tcell.EventKey) *tcell.EventKey { return key } +func (ui *UI) handleConfirmation(key *tcell.EventKey) *tcell.EventKey { + if key.Rune() == 'h' { + return tcell.NewEventKey(tcell.KeyLeft, 0, 0) + } + if key.Rune() == 'l' { + return tcell.NewEventKey(tcell.KeyRight, 0, 0) + } + return key +} + func (ui *UI) handleInfoPageEvents(key *tcell.EventKey) *tcell.EventKey { if ui.pages.HasPage("info") { switch key.Rune() { diff --git a/tui/keys_test.go b/tui/keys_test.go index eb52d1340..c0b3d4788 100644 --- a/tui/keys_test.go +++ b/tui/keys_test.go @@ -82,9 +82,13 @@ func TestLeftRightKeyWhileConfirm(t *testing.T) { modal := tview.NewModal().SetText("Really?") ui.pages.AddPage("confirm", modal, true, true) - key := ui.keyPressed(tcell.NewEventKey(tcell.KeyLeft, 'h', 0)) + key := ui.keyPressed(tcell.NewEventKey(tcell.KeyLeft, 0, 0)) assert.Equal(t, tcell.KeyLeft, key.Key()) - key = ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0)) + key = ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 0, 0)) + assert.Equal(t, tcell.KeyRight, key.Key()) + key = ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'h', 0)) + assert.Equal(t, tcell.KeyLeft, key.Key()) + key = ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'l', 0)) assert.Equal(t, tcell.KeyRight, key.Key()) }