Skip to content

Commit

Permalink
feat: handle vim-style navigation in confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
samihda authored and dundee committed Feb 12, 2024
1 parent 7ccd987 commit f2afa2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 15 additions & 2 deletions tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 6 additions & 2 deletions tui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down

0 comments on commit f2afa2a

Please sign in to comment.