Skip to content

Commit b2cbd93

Browse files
Add config option to disable switching tabs with panel jump keys (#3927)
# **PR Description** ## Problem this PR attempts to solve I really appreciate the feature added in #3794 that allows switching tabs using panel jump keys when the side panel is already active and see how it is convenient for many users. However, after using lazygit for quite some time, I've developed muscle memory where I rely on pressing a number key to instantly switch to a panel and perform an action, regardless of which panel is currently active. I have found myself several times in the past few days clicking '2' and going to hit 'a' + 'c' to commit all and find I was already had window 2 active and my tab was instead switched to 'Worktrees' and the keybindings no longer apply to stage or commit. ## Solution - Add a config `SwitchTabsWithPanelJumpKeys` as a gui boolean that is true by default, keeping the current new behavior added by #3794 - When `SwitchTabsWithPanelJumpKeys` is set to false in the user's config, the old behavior is returned which does not switch tabs using the side panel jump keys. - This is behavior is verified with an integration test with ``SwitchTabsWithPanelJumpKeys` set to false that shows the expected behavior that jumping to window 2 while window 2 is already active does not switch tabs within window 2 To disable switching tabs with panel jump keys, add the following to your config.yml: ```yaml gui: # If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead switchTabsWithPanelJumpKeys: false ``` ### P.S. This is my first contribution to lazygit and while I absolutely strived to read all documentation and follow all standards, I accept that this PR may not be perfect and am very open to feedback and suggestions to improve both this code and any future contributions. I absolutely love lazygit, I use it everyday and swear by it as the most powerful and efficient tool for managing git, I love and appreciate all the work all the maintainers do to constantly improve it. So thank you to all who are reading this and I look forward to contributing more to make lazygit even more of the best git tool available! * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] No text rendered to user -> Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [x] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
2 parents 7edf629 + 8da43af commit b2cbd93

File tree

7 files changed

+44
-3
lines changed

7 files changed

+44
-3
lines changed

docs/Config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ gui:
252252
# If true, jump to the Files panel after applying a stash
253253
switchToFilesAfterStashApply: true
254254

255+
# If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead
256+
switchTabsWithPanelJumpKeys: false
257+
255258
# Config relating to git
256259
git:
257260
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md

pkg/config/user_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ type GuiConfig struct {
165165
SwitchToFilesAfterStashPop bool `yaml:"switchToFilesAfterStashPop"`
166166
// If true, jump to the Files panel after applying a stash
167167
SwitchToFilesAfterStashApply bool `yaml:"switchToFilesAfterStashApply"`
168+
// If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead
169+
SwitchTabsWithPanelJumpKeys bool `yaml:"switchTabsWithPanelJumpKeys"`
168170
}
169171

170172
func (c *GuiConfig) UseFuzzySearch() bool {
@@ -736,6 +738,7 @@ func GetDefaultConfig() *UserConfig {
736738
StatusPanelView: "dashboard",
737739
SwitchToFilesAfterStashPop: true,
738740
SwitchToFilesAfterStashApply: true,
741+
SwitchTabsWithPanelJumpKeys: false,
739742
},
740743
Git: GitConfig{
741744
Paging: PagingConfig{

pkg/gui/controllers/jump_to_side_window_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpt
4949

5050
func (self *JumpToSideWindowController) goToSideWindow(window string) func() error {
5151
return func() error {
52-
if self.c.Helpers().Window.CurrentWindow() == window {
52+
sideWindowAlreadyActive := self.c.Helpers().Window.CurrentWindow() == window
53+
if sideWindowAlreadyActive && self.c.UserConfig().Gui.SwitchTabsWithPanelJumpKeys {
5354
return self.nextTabFunc()
5455
}
5556

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ var tests = []*components.IntegrationTest{
346346
tag.ForceTagLightweight,
347347
tag.Reset,
348348
ui.Accordion,
349+
ui.DisableSwitchTabWithPanelJumpKeys,
349350
ui.DoublePopup,
350351
ui.EmptyMenu,
351352
ui.KeybindingSuggestionsWhenSwitchingRepos,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 DisableSwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Verify that the tab does not change by default when jumping to an already focused panel",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
},
16+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
17+
t.Views().Status().Focus().
18+
Press(keys.Universal.JumpToBlock[1])
19+
t.Views().Files().IsFocused().
20+
Press(keys.Universal.JumpToBlock[1])
21+
22+
// Despite jumping to an already focused panel,
23+
// the tab should not change from the base files view
24+
t.Views().Files().IsFocused()
25+
},
26+
})

pkg/integration/tests/ui/switch_tab_with_panel_jump_keys.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
)
77

88
var SwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{
9-
Description: "Switch tab with the panel jump keys",
9+
Description: "Switch tab with the panel jump keys after enabling the feature",
1010
ExtraCmdArgs: []string{},
1111
Skip: false,
12-
SetupConfig: func(config *config.AppConfig) {},
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.GetUserConfig().Gui.SwitchTabsWithPanelJumpKeys = true
14+
},
1315
SetupRepo: func(shell *Shell) {
1416
},
1517
Run: func(t *TestDriver, keys config.KeybindingConfig) {

schema/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@
462462
"type": "boolean",
463463
"description": "If true, jump to the Files panel after applying a stash",
464464
"default": true
465+
},
466+
"switchTabsWithPanelJumpKeys": {
467+
"type": "boolean",
468+
"description": "If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead",
469+
"default": false
465470
}
466471
},
467472
"additionalProperties": false,

0 commit comments

Comments
 (0)