From c410af87d9e1a7d339544cd9846bc62d5e770f1c Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 8 Apr 2023 23:37:29 +0200 Subject: [PATCH] fix: do not show help modal when confirm modal is already opened (#237) --- tui/keys.go | 54 ++++++++++++++++++++++++++++++++++++++---------- tui/keys_test.go | 4 ++++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/tui/keys.go b/tui/keys.go index 945d1abbc..730534c32 100644 --- a/tui/keys.go +++ b/tui/keys.go @@ -23,7 +23,7 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { if key == nil { return nil } - key = ui.handleBreakingActions(key) + key = ui.handleQuit(key) if key == nil { return nil } @@ -31,19 +31,31 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { if ui.pages.HasPage("confirm") || ui.pages.HasPage("progress") || ui.pages.HasPage("deleting") || - ui.pages.HasPage("emptying") || - ui.pages.HasPage("help") { + ui.pages.HasPage("emptying") { return key } + key = ui.handleHelp(key) + if key == nil { + return nil + } + + if ui.pages.HasPage("help") { + return key + } + + key = ui.handleShell(key) + if key == nil { + return nil + } + key = ui.handleLeftRight(key) if key == nil { return nil } - if key.Key() == tcell.KeyTab && ui.filteringInput != nil { - ui.filtering = true - ui.app.SetFocus(ui.filteringInput) + key = ui.handleFiltering(key) + if key == nil { return nil } @@ -95,7 +107,7 @@ func (ui *UI) handleInfoPageEvents(key *tcell.EventKey) *tcell.EventKey { return key } -func (ui *UI) handleBreakingActions(key *tcell.EventKey) *tcell.EventKey { +func (ui *UI) handleQuit(key *tcell.EventKey) *tcell.EventKey { switch key.Rune() { case 'Q': ui.app.Stop() @@ -104,16 +116,27 @@ func (ui *UI) handleBreakingActions(key *tcell.EventKey) *tcell.EventKey { case 'q': ui.app.Stop() return nil - case 'b': - ui.spawnShell() - return nil - case '?': + } + return key +} + +func (ui *UI) handleHelp(key *tcell.EventKey) *tcell.EventKey { + if key.Rune() == '?' { if ui.pages.HasPage("help") { ui.pages.RemovePage("help") ui.app.SetFocus(ui.table) return nil } ui.showHelp() + return nil + } + return key +} + +func (ui *UI) handleShell(key *tcell.EventKey) *tcell.EventKey { + if key.Rune() == 'b' { + ui.spawnShell() + return nil } return key } @@ -131,6 +154,15 @@ func (ui *UI) handleLeftRight(key *tcell.EventKey) *tcell.EventKey { return key } +func (ui *UI) handleFiltering(key *tcell.EventKey) *tcell.EventKey { + if key.Key() == tcell.KeyTab && ui.filteringInput != nil { + ui.filtering = true + ui.app.SetFocus(ui.filteringInput) + return nil + } + return key +} + func (ui *UI) handleMainActions(key *tcell.EventKey) *tcell.EventKey { switch key.Rune() { case 'd': diff --git a/tui/keys_test.go b/tui/keys_test.go index 0b2904343..35be99ba9 100644 --- a/tui/keys_test.go +++ b/tui/keys_test.go @@ -330,6 +330,10 @@ func TestShowConfirm(t *testing.T) { ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'd', 0)) assert.True(t, ui.pages.HasPage("confirm")) + + ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, '?', 0)) + + assert.False(t, ui.pages.HasPage("help")) } func TestDeleteEmpty(t *testing.T) {