From 8da43af9245a60d671a6466f7bc0cb0484bf9ae2 Mon Sep 17 00:00:00 2001 From: Harris Greenstein Date: Sat, 9 Nov 2024 17:04:44 +1100 Subject: [PATCH] Add config option to disable tab switching with jump keys --- docs/Config.md | 3 +++ pkg/config/user_config.go | 3 +++ .../jump_to_side_window_controller.go | 3 ++- pkg/integration/tests/test_list.go | 1 + ...disable_switch_tab_with_panel_jump_keys.go | 26 +++++++++++++++++++ .../ui/switch_tab_with_panel_jump_keys.go | 6 +++-- schema/config.json | 5 ++++ 7 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 pkg/integration/tests/ui/disable_switch_tab_with_panel_jump_keys.go diff --git a/docs/Config.md b/docs/Config.md index 432e70186..d63987f06 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -252,6 +252,9 @@ gui: # If true, jump to the Files panel after applying a stash switchToFilesAfterStashApply: true + # 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 + # Config relating to git git: # See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 2a8778ef9..b02a959f5 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -165,6 +165,8 @@ type GuiConfig struct { SwitchToFilesAfterStashPop bool `yaml:"switchToFilesAfterStashPop"` // If true, jump to the Files panel after applying a stash SwitchToFilesAfterStashApply bool `yaml:"switchToFilesAfterStashApply"` + // If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead + SwitchTabsWithPanelJumpKeys bool `yaml:"switchTabsWithPanelJumpKeys"` } func (c *GuiConfig) UseFuzzySearch() bool { @@ -736,6 +738,7 @@ func GetDefaultConfig() *UserConfig { StatusPanelView: "dashboard", SwitchToFilesAfterStashPop: true, SwitchToFilesAfterStashApply: true, + SwitchTabsWithPanelJumpKeys: false, }, Git: GitConfig{ Paging: PagingConfig{ diff --git a/pkg/gui/controllers/jump_to_side_window_controller.go b/pkg/gui/controllers/jump_to_side_window_controller.go index f6917f5b4..39120eda8 100644 --- a/pkg/gui/controllers/jump_to_side_window_controller.go +++ b/pkg/gui/controllers/jump_to_side_window_controller.go @@ -49,7 +49,8 @@ func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpt func (self *JumpToSideWindowController) goToSideWindow(window string) func() error { return func() error { - if self.c.Helpers().Window.CurrentWindow() == window { + sideWindowAlreadyActive := self.c.Helpers().Window.CurrentWindow() == window + if sideWindowAlreadyActive && self.c.UserConfig().Gui.SwitchTabsWithPanelJumpKeys { return self.nextTabFunc() } diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 0c0142e40..5c4669543 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -346,6 +346,7 @@ var tests = []*components.IntegrationTest{ tag.ForceTagLightweight, tag.Reset, ui.Accordion, + ui.DisableSwitchTabWithPanelJumpKeys, ui.DoublePopup, ui.EmptyMenu, ui.KeybindingSuggestionsWhenSwitchingRepos, diff --git a/pkg/integration/tests/ui/disable_switch_tab_with_panel_jump_keys.go b/pkg/integration/tests/ui/disable_switch_tab_with_panel_jump_keys.go new file mode 100644 index 000000000..fb1ba5aba --- /dev/null +++ b/pkg/integration/tests/ui/disable_switch_tab_with_panel_jump_keys.go @@ -0,0 +1,26 @@ +package ui + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DisableSwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify that the tab does not change by default when jumping to an already focused panel", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Status().Focus(). + Press(keys.Universal.JumpToBlock[1]) + t.Views().Files().IsFocused(). + Press(keys.Universal.JumpToBlock[1]) + + // Despite jumping to an already focused panel, + // the tab should not change from the base files view + t.Views().Files().IsFocused() + }, +}) diff --git a/pkg/integration/tests/ui/switch_tab_with_panel_jump_keys.go b/pkg/integration/tests/ui/switch_tab_with_panel_jump_keys.go index cd2635223..4411cb3c6 100644 --- a/pkg/integration/tests/ui/switch_tab_with_panel_jump_keys.go +++ b/pkg/integration/tests/ui/switch_tab_with_panel_jump_keys.go @@ -6,10 +6,12 @@ import ( ) var SwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Switch tab with the panel jump keys", + Description: "Switch tab with the panel jump keys after enabling the feature", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.SwitchTabsWithPanelJumpKeys = true + }, SetupRepo: func(shell *Shell) { }, Run: func(t *TestDriver, keys config.KeybindingConfig) { diff --git a/schema/config.json b/schema/config.json index 78e932f9d..876a5bab9 100644 --- a/schema/config.json +++ b/schema/config.json @@ -462,6 +462,11 @@ "type": "boolean", "description": "If true, jump to the Files panel after applying a stash", "default": true + }, + "switchTabsWithPanelJumpKeys": { + "type": "boolean", + "description": "If true, when using the panel jump keys (default 1 through 5) and target panel is already active, go to next tab instead", + "default": false } }, "additionalProperties": false,