Skip to content

Commit

Permalink
fix: do not show help modal when confirm modal is already opened (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee authored Apr 8, 2023
1 parent e18c125 commit c410af8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
54 changes: 43 additions & 11 deletions tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,39 @@ 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
}

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
}

Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand All @@ -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':
Expand Down
4 changes: 4 additions & 0 deletions tui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c410af8

Please sign in to comment.