Skip to content

Commit 69666d1

Browse files
authored
Switch tabs with panel jump keys (#3794)
- **PR Description** When using the panel jump keybindings (`1` through `5` by default), and the target panel is already the active one, go to the next tab instead.
2 parents c72be6c + b37d6dc commit 69666d1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

pkg/gui/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (gui *Gui) resetHelpersAndControllers() {
197197
commandLogController := controllers.NewCommandLogController(common)
198198
confirmationController := controllers.NewConfirmationController(common)
199199
suggestionsController := controllers.NewSuggestionsController(common)
200-
jumpToSideWindowController := controllers.NewJumpToSideWindowController(common)
200+
jumpToSideWindowController := controllers.NewJumpToSideWindowController(common, gui.handleNextTab)
201201

202202
sideWindowControllerFactory := controllers.NewSideWindowControllerFactory(common)
203203

pkg/gui/controllers/jump_to_side_window_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import (
1010

1111
type JumpToSideWindowController struct {
1212
baseController
13-
c *ControllerCommon
13+
c *ControllerCommon
14+
nextTabFunc func() error
1415
}
1516

1617
func NewJumpToSideWindowController(
1718
c *ControllerCommon,
19+
nextTabFunc func() error,
1820
) *JumpToSideWindowController {
1921
return &JumpToSideWindowController{
2022
baseController: baseController{},
2123
c: c,
24+
nextTabFunc: nextTabFunc,
2225
}
2326
}
2427

@@ -46,6 +49,10 @@ func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpt
4649

4750
func (self *JumpToSideWindowController) goToSideWindow(window string) func() error {
4851
return func() error {
52+
if self.c.Helpers().Window.CurrentWindow() == window {
53+
return self.nextTabFunc()
54+
}
55+
4956
context := self.c.Helpers().Window.GetContextForWindow(window)
5057

5158
return self.c.PushContext(context)

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ var tests = []*components.IntegrationTest{
338338
ui.OpenLinkFailure,
339339
ui.RangeSelect,
340340
ui.SwitchTabFromMenu,
341+
ui.SwitchTabWithPanelJumpKeys,
341342
undo.UndoCheckoutAndDrop,
342343
undo.UndoDrop,
343344
worktree.AddFromBranch,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ui
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var SwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Switch tab with the panel jump keys",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
},
15+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
16+
t.Views().Worktrees().Focus().
17+
Press(keys.Universal.JumpToBlock[2])
18+
19+
t.Views().Branches().IsFocused().
20+
Press(keys.Universal.JumpToBlock[2])
21+
22+
t.Views().Remotes().IsFocused().
23+
Press(keys.Universal.JumpToBlock[2])
24+
25+
t.Views().Tags().IsFocused().
26+
Press(keys.Universal.JumpToBlock[2])
27+
28+
t.Views().Branches().IsFocused().
29+
Press(keys.Universal.JumpToBlock[1])
30+
31+
// When jumping to a panel from a different one, keep its current tab:
32+
t.Views().Worktrees().IsFocused()
33+
},
34+
})

0 commit comments

Comments
 (0)