summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Milde <daniel@milde.cz>2023-04-08 23:37:29 +0200
committerGitHub <noreply@github.com>2023-04-08 23:37:29 +0200
commitc410af87d9e1a7d339544cd9846bc62d5e770f1c (patch)
tree724e01834dcab88671e8c8119310257f81ec4891
parente18c1255d5d6730cf88acbf35d3a193a1e703865 (diff)
fix: do not show help modal when confirm modal is already opened (#237)v5.23.0
-rw-r--r--tui/keys.go54
-rw-r--r--tui/keys_test.go4
2 files changed, 47 insertions, 11 deletions
diff --git a/tui/keys.go b/tui/keys.go
index 945d1ab..730534c 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 0b29043..35be99b 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) {