Skip to content

Commit 3cdf0b1

Browse files
Add shift+tab to switch to previous tab
1 parent 04d2ae0 commit 3cdf0b1

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

internal/ui/app.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ func (a *App) nextTab() {
131131
}
132132
}
133133

134+
func (a *App) prevTab() {
135+
for i, t := range a.tabs {
136+
if t == a.activeTab {
137+
a.switchTab(a.tabs[(i-1+len(a.tabs))%len(a.tabs)])
138+
return
139+
}
140+
}
141+
}
142+
134143
type tickMsg struct{}
135144
type fetchMsg struct {
136145
snap *fetcher.Snapshot
@@ -432,6 +441,9 @@ func (a *App) handleListKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
432441
case "tab":
433442
a.nextTab()
434443
return a, nil
444+
case "shift+tab":
445+
a.prevTab()
446+
return a, nil
435447
case "1":
436448
if len(a.tabs) > 0 {
437449
a.switchTab(a.tabs[0])

internal/ui/app_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,41 @@ func TestTabSwitch_TabKey(t *testing.T) {
557557
assert.Equal(t, tabFrankenPHP, app.activeTab)
558558
}
559559

560+
func TestTabSwitch_ShiftTabKey(t *testing.T) {
561+
app := newAppWithThreads([]fetcher.ThreadDebugState{{Index: 0, IsWaiting: true}})
562+
assert.Equal(t, tabFrankenPHP, app.activeTab)
563+
564+
app.handleListKey(tea.KeyMsg{Type: tea.KeyShiftTab})
565+
assert.Equal(t, tabCaddy, app.activeTab)
566+
567+
app.handleListKey(tea.KeyMsg{Type: tea.KeyShiftTab})
568+
assert.Equal(t, tabFrankenPHP, app.activeTab)
569+
}
570+
571+
func TestTabSwitch_ShiftTabReversesTab(t *testing.T) {
572+
app := newAppWithThreads([]fetcher.ThreadDebugState{{Index: 0, IsWaiting: true}})
573+
assert.Equal(t, tabFrankenPHP, app.activeTab)
574+
575+
app.handleListKey(tea.KeyMsg{Type: tea.KeyTab})
576+
assert.Equal(t, tabCaddy, app.activeTab)
577+
578+
app.handleListKey(tea.KeyMsg{Type: tea.KeyShiftTab})
579+
assert.Equal(t, tabFrankenPHP, app.activeTab, "Shift+Tab should reverse Tab direction")
580+
}
581+
582+
func TestTabSwitch_ShiftTabPreservesCursorPerTab(t *testing.T) {
583+
app := newAppWithThreads([]fetcher.ThreadDebugState{
584+
{Index: 0}, {Index: 1}, {Index: 2},
585+
})
586+
app.cursor = 2
587+
588+
app.handleListKey(tea.KeyMsg{Type: tea.KeyShiftTab})
589+
assert.Equal(t, 0, app.cursor, "Caddy tab should start at cursor 0")
590+
591+
app.handleListKey(tea.KeyMsg{Type: tea.KeyShiftTab})
592+
assert.Equal(t, 2, app.cursor, "FrankenPHP tab should restore cursor")
593+
}
594+
560595
func TestTabSwitch_NumberKeys(t *testing.T) {
561596
app := newAppWithThreads([]fetcher.ThreadDebugState{{Index: 0, IsWaiting: true}})
562597

internal/ui/help.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func renderHelp(sortBy model.SortField, hostSortBy model.HostSortField, paused b
3737
bindings = append(bindings,
3838
binding{"g", "graphs"},
3939
binding{"/", "filter"},
40-
binding{"Tab", "switch"},
40+
binding{"Tab/S-Tab", "switch"},
4141
binding{"q", "quit"},
4242
)
4343

@@ -60,7 +60,7 @@ func renderHelpOverlay(base string, width, height int, hasFrankenPHP bool) strin
6060
{"↑/↓ j/k", "Move cursor"},
6161
{"Enter", "Open detail panel"},
6262
{"Esc", "Close / go back"},
63-
{"Tab", "Switch tab"},
63+
{"Tab/S-Tab", "Switch tab"},
6464
{"1/2", "Jump to tab"},
6565
{"Home/End", "Jump to first/last"},
6666
{"PgUp/PgDn", "Page up/down"},

0 commit comments

Comments
 (0)