diff --git a/pkg/config/keybinding_test.go b/pkg/config/keybinding_test.go index 9bf3ed442..a0bff786c 100644 --- a/pkg/config/keybinding_test.go +++ b/pkg/config/keybinding_test.go @@ -180,3 +180,18 @@ func TestKeybindingConfigYAMLAcceptsBothForms(t *testing.T) { }) } } + +func TestJumpToBlockYAMLAcceptsMixedForms(t *testing.T) { + yamlInput := ` +jumpToBlock: + - "1" + - ["2", "@"] + - "3" + - "4" + - "5" +` + var cfg KeybindingUniversalConfig + assert.NoError(t, yaml.Unmarshal([]byte(yamlInput), &cfg)) + expected := []Keybinding{{"1"}, {"2", "@"}, {"3"}, {"4"}, {"5"}} + assert.Equal(t, expected, cfg.JumpToBlock) +} diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index bbd568e8d..dfeced3c0 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -423,86 +423,86 @@ type KeybindingConfig struct { // damn looks like we have some inconsistencies here with -alt and -alt1 type KeybindingUniversalConfig struct { - Quit Keybinding `yaml:"quit"` - QuitAlt1 Keybinding `yaml:"quit-alt1"` - SuspendApp Keybinding `yaml:"suspendApp"` - Return Keybinding `yaml:"return"` - QuitWithoutChangingDirectory Keybinding `yaml:"quitWithoutChangingDirectory"` - TogglePanel Keybinding `yaml:"togglePanel"` - PrevItem Keybinding `yaml:"prevItem"` - NextItem Keybinding `yaml:"nextItem"` - PrevItemAlt Keybinding `yaml:"prevItem-alt"` - NextItemAlt Keybinding `yaml:"nextItem-alt"` - PrevPage Keybinding `yaml:"prevPage"` - NextPage Keybinding `yaml:"nextPage"` - ScrollLeft Keybinding `yaml:"scrollLeft"` - ScrollRight Keybinding `yaml:"scrollRight"` - GotoTop Keybinding `yaml:"gotoTop"` - GotoBottom Keybinding `yaml:"gotoBottom"` - GotoTopAlt Keybinding `yaml:"gotoTop-alt"` - GotoBottomAlt Keybinding `yaml:"gotoBottom-alt"` - ToggleRangeSelect Keybinding `yaml:"toggleRangeSelect"` - RangeSelectDown Keybinding `yaml:"rangeSelectDown"` - RangeSelectUp Keybinding `yaml:"rangeSelectUp"` - PrevBlock Keybinding `yaml:"prevBlock"` - NextBlock Keybinding `yaml:"nextBlock"` - PrevBlockAlt Keybinding `yaml:"prevBlock-alt"` - NextBlockAlt Keybinding `yaml:"nextBlock-alt"` - NextBlockAlt2 Keybinding `yaml:"nextBlock-alt2"` - PrevBlockAlt2 Keybinding `yaml:"prevBlock-alt2"` - JumpToBlock []string `yaml:"jumpToBlock"` - FocusMainView Keybinding `yaml:"focusMainView"` - NextMatch Keybinding `yaml:"nextMatch"` - PrevMatch Keybinding `yaml:"prevMatch"` - StartSearch Keybinding `yaml:"startSearch"` - MoveWordLeft Keybinding `yaml:"moveWordLeft"` // on Mac - MoveWordRight Keybinding `yaml:"moveWordRight"` // on Mac - BackspaceWord Keybinding `yaml:"backspaceWord"` // on Mac - ForwardDeleteWord Keybinding `yaml:"forwardDeleteWord"` // on Mac - OptionMenu Keybinding `yaml:"optionMenu"` - Select Keybinding `yaml:"select"` - GoInto Keybinding `yaml:"goInto"` - Confirm Keybinding `yaml:"confirm"` - ConfirmMenu Keybinding `yaml:"confirmMenu"` - ConfirmSuggestion Keybinding `yaml:"confirmSuggestion"` - ConfirmInEditor Keybinding `yaml:"confirmInEditor"` // on Mac - ConfirmInEditorAlt Keybinding `yaml:"confirmInEditor-alt"` - Remove Keybinding `yaml:"remove"` - New Keybinding `yaml:"new"` - Edit Keybinding `yaml:"edit"` - OpenFile Keybinding `yaml:"openFile"` - ScrollUpMain Keybinding `yaml:"scrollUpMain"` - ScrollDownMain Keybinding `yaml:"scrollDownMain"` - ScrollUpMainAlt1 Keybinding `yaml:"scrollUpMain-alt1"` - ScrollDownMainAlt1 Keybinding `yaml:"scrollDownMain-alt1"` - ScrollUpMainAlt2 Keybinding `yaml:"scrollUpMain-alt2"` - ScrollDownMainAlt2 Keybinding `yaml:"scrollDownMain-alt2"` - ExecuteShellCommand Keybinding `yaml:"executeShellCommand"` - CreateRebaseOptionsMenu Keybinding `yaml:"createRebaseOptionsMenu"` - Push Keybinding `yaml:"pushFiles"` // 'Files' appended for legacy reasons - Pull Keybinding `yaml:"pullFiles"` // 'Files' appended for legacy reasons - Refresh Keybinding `yaml:"refresh"` - CreatePatchOptionsMenu Keybinding `yaml:"createPatchOptionsMenu"` - NextTab Keybinding `yaml:"nextTab"` - PrevTab Keybinding `yaml:"prevTab"` - NextScreenMode Keybinding `yaml:"nextScreenMode"` - PrevScreenMode Keybinding `yaml:"prevScreenMode"` - CyclePagers Keybinding `yaml:"cyclePagers"` - Undo Keybinding `yaml:"undo"` - Redo Keybinding `yaml:"redo"` - FilteringMenu Keybinding `yaml:"filteringMenu"` - DiffingMenu Keybinding `yaml:"diffingMenu"` - DiffingMenuAlt Keybinding `yaml:"diffingMenu-alt"` - CopyToClipboard Keybinding `yaml:"copyToClipboard"` - OpenRecentRepos Keybinding `yaml:"openRecentRepos"` - SubmitEditorText Keybinding `yaml:"submitEditorText"` - ExtrasMenu Keybinding `yaml:"extrasMenu"` - ToggleWhitespaceInDiffView Keybinding `yaml:"toggleWhitespaceInDiffView"` - IncreaseContextInDiffView Keybinding `yaml:"increaseContextInDiffView"` - DecreaseContextInDiffView Keybinding `yaml:"decreaseContextInDiffView"` - IncreaseRenameSimilarityThreshold Keybinding `yaml:"increaseRenameSimilarityThreshold"` - DecreaseRenameSimilarityThreshold Keybinding `yaml:"decreaseRenameSimilarityThreshold"` - OpenDiffTool Keybinding `yaml:"openDiffTool"` + Quit Keybinding `yaml:"quit"` + QuitAlt1 Keybinding `yaml:"quit-alt1"` + SuspendApp Keybinding `yaml:"suspendApp"` + Return Keybinding `yaml:"return"` + QuitWithoutChangingDirectory Keybinding `yaml:"quitWithoutChangingDirectory"` + TogglePanel Keybinding `yaml:"togglePanel"` + PrevItem Keybinding `yaml:"prevItem"` + NextItem Keybinding `yaml:"nextItem"` + PrevItemAlt Keybinding `yaml:"prevItem-alt"` + NextItemAlt Keybinding `yaml:"nextItem-alt"` + PrevPage Keybinding `yaml:"prevPage"` + NextPage Keybinding `yaml:"nextPage"` + ScrollLeft Keybinding `yaml:"scrollLeft"` + ScrollRight Keybinding `yaml:"scrollRight"` + GotoTop Keybinding `yaml:"gotoTop"` + GotoBottom Keybinding `yaml:"gotoBottom"` + GotoTopAlt Keybinding `yaml:"gotoTop-alt"` + GotoBottomAlt Keybinding `yaml:"gotoBottom-alt"` + ToggleRangeSelect Keybinding `yaml:"toggleRangeSelect"` + RangeSelectDown Keybinding `yaml:"rangeSelectDown"` + RangeSelectUp Keybinding `yaml:"rangeSelectUp"` + PrevBlock Keybinding `yaml:"prevBlock"` + NextBlock Keybinding `yaml:"nextBlock"` + PrevBlockAlt Keybinding `yaml:"prevBlock-alt"` + NextBlockAlt Keybinding `yaml:"nextBlock-alt"` + NextBlockAlt2 Keybinding `yaml:"nextBlock-alt2"` + PrevBlockAlt2 Keybinding `yaml:"prevBlock-alt2"` + JumpToBlock []Keybinding `yaml:"jumpToBlock"` + FocusMainView Keybinding `yaml:"focusMainView"` + NextMatch Keybinding `yaml:"nextMatch"` + PrevMatch Keybinding `yaml:"prevMatch"` + StartSearch Keybinding `yaml:"startSearch"` + MoveWordLeft Keybinding `yaml:"moveWordLeft"` // on Mac + MoveWordRight Keybinding `yaml:"moveWordRight"` // on Mac + BackspaceWord Keybinding `yaml:"backspaceWord"` // on Mac + ForwardDeleteWord Keybinding `yaml:"forwardDeleteWord"` // on Mac + OptionMenu Keybinding `yaml:"optionMenu"` + Select Keybinding `yaml:"select"` + GoInto Keybinding `yaml:"goInto"` + Confirm Keybinding `yaml:"confirm"` + ConfirmMenu Keybinding `yaml:"confirmMenu"` + ConfirmSuggestion Keybinding `yaml:"confirmSuggestion"` + ConfirmInEditor Keybinding `yaml:"confirmInEditor"` // on Mac + ConfirmInEditorAlt Keybinding `yaml:"confirmInEditor-alt"` + Remove Keybinding `yaml:"remove"` + New Keybinding `yaml:"new"` + Edit Keybinding `yaml:"edit"` + OpenFile Keybinding `yaml:"openFile"` + ScrollUpMain Keybinding `yaml:"scrollUpMain"` + ScrollDownMain Keybinding `yaml:"scrollDownMain"` + ScrollUpMainAlt1 Keybinding `yaml:"scrollUpMain-alt1"` + ScrollDownMainAlt1 Keybinding `yaml:"scrollDownMain-alt1"` + ScrollUpMainAlt2 Keybinding `yaml:"scrollUpMain-alt2"` + ScrollDownMainAlt2 Keybinding `yaml:"scrollDownMain-alt2"` + ExecuteShellCommand Keybinding `yaml:"executeShellCommand"` + CreateRebaseOptionsMenu Keybinding `yaml:"createRebaseOptionsMenu"` + Push Keybinding `yaml:"pushFiles"` // 'Files' appended for legacy reasons + Pull Keybinding `yaml:"pullFiles"` // 'Files' appended for legacy reasons + Refresh Keybinding `yaml:"refresh"` + CreatePatchOptionsMenu Keybinding `yaml:"createPatchOptionsMenu"` + NextTab Keybinding `yaml:"nextTab"` + PrevTab Keybinding `yaml:"prevTab"` + NextScreenMode Keybinding `yaml:"nextScreenMode"` + PrevScreenMode Keybinding `yaml:"prevScreenMode"` + CyclePagers Keybinding `yaml:"cyclePagers"` + Undo Keybinding `yaml:"undo"` + Redo Keybinding `yaml:"redo"` + FilteringMenu Keybinding `yaml:"filteringMenu"` + DiffingMenu Keybinding `yaml:"diffingMenu"` + DiffingMenuAlt Keybinding `yaml:"diffingMenu-alt"` + CopyToClipboard Keybinding `yaml:"copyToClipboard"` + OpenRecentRepos Keybinding `yaml:"openRecentRepos"` + SubmitEditorText Keybinding `yaml:"submitEditorText"` + ExtrasMenu Keybinding `yaml:"extrasMenu"` + ToggleWhitespaceInDiffView Keybinding `yaml:"toggleWhitespaceInDiffView"` + IncreaseContextInDiffView Keybinding `yaml:"increaseContextInDiffView"` + DecreaseContextInDiffView Keybinding `yaml:"decreaseContextInDiffView"` + IncreaseRenameSimilarityThreshold Keybinding `yaml:"increaseRenameSimilarityThreshold"` + DecreaseRenameSimilarityThreshold Keybinding `yaml:"decreaseRenameSimilarityThreshold"` + OpenDiffTool Keybinding `yaml:"openDiffTool"` } type KeybindingStatusConfig struct { @@ -932,7 +932,7 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { NextBlockAlt: Keybinding{"l"}, PrevBlockAlt2: Keybinding{""}, NextBlockAlt2: Keybinding{""}, - JumpToBlock: []string{"1", "2", "3", "4", "5"}, + JumpToBlock: []Keybinding{{"1"}, {"2"}, {"3"}, {"4"}, {"5"}}, FocusMainView: Keybinding{"0"}, NextMatch: Keybinding{"n"}, PrevMatch: Keybinding{"N"}, diff --git a/pkg/config/user_config_validation_test.go b/pkg/config/user_config_validation_test.go index 6474ac3b0..ec79c9c3e 100644 --- a/pkg/config/user_config_validation_test.go +++ b/pkg/config/user_config_validation_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/samber/lo" "github.com/stretchr/testify/assert" ) @@ -127,7 +128,10 @@ func TestUserConfigValidate_enums(t *testing.T) { { name: "JumpToBlock keybinding", setup: func(config *UserConfig, value string) { - config.Keybinding.Universal.JumpToBlock = strings.Split(value, ",") + labels := strings.Split(value, ",") + config.Keybinding.Universal.JumpToBlock = lo.Map(labels, func(label string, _ int) Keybinding { + return Keybinding{label} + }) }, testCases: []testCase{ {value: "", valid: false}, diff --git a/pkg/gui/controllers/jump_to_side_window_controller.go b/pkg/gui/controllers/jump_to_side_window_controller.go index 31228e3a6..2ea8ac762 100644 --- a/pkg/gui/controllers/jump_to_side_window_controller.go +++ b/pkg/gui/controllers/jump_to_side_window_controller.go @@ -3,7 +3,6 @@ package controllers import ( "log" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" ) @@ -40,7 +39,7 @@ func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpt return &types.Binding{ ViewName: "", // by default the keys are 1, 2, 3, etc - Keys: opts.GetKeys(config.Keybinding{opts.Config.Universal.JumpToBlock[index]}), + Keys: opts.GetKeys(opts.Config.Universal.JumpToBlock[index]), Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(window)), } }) diff --git a/pkg/gui/views.go b/pkg/gui/views.go index 297da143f..ecfc0ddcd 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/theme" @@ -210,14 +211,14 @@ func (gui *Gui) configureViewProperties() { gui.Views.CommitDescription.TextArea.AutoWrapWidth = gui.c.UserConfig().Git.Commit.AutoWrapWidth if gui.c.UserConfig().Gui.ShowPanelJumps { - keyToTitlePrefix := func(key string) string { - if key == "" { + keyToTitlePrefix := func(binding config.Keybinding) string { + if len(binding) == 0 { return "" } - return fmt.Sprintf("[%s]", key) + return fmt.Sprintf("[%s]", binding[0]) } jumpBindings := gui.c.UserConfig().Keybinding.Universal.JumpToBlock - jumpLabels := lo.Map(jumpBindings, func(binding string, _ int) string { + jumpLabels := lo.Map(jumpBindings, func(binding config.Keybinding, _ int) string { return keyToTitlePrefix(binding) }) @@ -236,7 +237,7 @@ func (gui *Gui) configureViewProperties() { gui.Views.Stash.TitlePrefix = jumpLabels[4] - gui.Views.Main.TitlePrefix = keyToTitlePrefix(gui.c.UserConfig().Keybinding.Universal.FocusMainView[0]) + gui.Views.Main.TitlePrefix = keyToTitlePrefix(gui.c.UserConfig().Keybinding.Universal.FocusMainView) } else { gui.Views.Status.TitlePrefix = "" diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go index 8b1650c32..e9e5fbbc7 100644 --- a/pkg/integration/components/view_driver.go +++ b/pkg/integration/components/view_driver.go @@ -363,7 +363,7 @@ func (self *ViewDriver) Focus() *ViewDriver { if lo.Contains(window.viewNames, viewName) { tabIndex := lo.IndexOf(window.viewNames, viewName) // jump to the desired window - self.t.press(self.t.keys.Universal.JumpToBlock[windowIndex]) + self.t.press(self.t.keys.Universal.JumpToBlock[windowIndex][0]) // assert we're in the window before continuing self.t.assertWithRetries(func() (bool, string) { 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 index 4ca3d1475..fb1ba5aba 100644 --- 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 @@ -15,9 +15,9 @@ var DisableSwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArg }, Run: func(t *TestDriver, keys config.KeybindingConfig) { t.Views().Status().Focus(). - Press(config.Keybinding{keys.Universal.JumpToBlock[1]}) + Press(keys.Universal.JumpToBlock[1]) t.Views().Files().IsFocused(). - Press(config.Keybinding{keys.Universal.JumpToBlock[1]}) + Press(keys.Universal.JumpToBlock[1]) // Despite jumping to an already focused panel, // the tab should not change from the base files view 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 25676a7ed..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 @@ -16,19 +16,19 @@ var SwitchTabWithPanelJumpKeys = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(t *TestDriver, keys config.KeybindingConfig) { t.Views().Worktrees().Focus(). - Press(config.Keybinding{keys.Universal.JumpToBlock[2]}) + Press(keys.Universal.JumpToBlock[2]) t.Views().Branches().IsFocused(). - Press(config.Keybinding{keys.Universal.JumpToBlock[2]}) + Press(keys.Universal.JumpToBlock[2]) t.Views().Remotes().IsFocused(). - Press(config.Keybinding{keys.Universal.JumpToBlock[2]}) + Press(keys.Universal.JumpToBlock[2]) t.Views().Tags().IsFocused(). - Press(config.Keybinding{keys.Universal.JumpToBlock[2]}) + Press(keys.Universal.JumpToBlock[2]) t.Views().Branches().IsFocused(). - Press(config.Keybinding{keys.Universal.JumpToBlock[1]}) + Press(keys.Universal.JumpToBlock[1]) // When jumping to a panel from a different one, keep its current tab: t.Views().Worktrees().IsFocused() diff --git a/schema-master/config.json b/schema-master/config.json index f2ba2ad46..495acc1d2 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -2473,7 +2473,17 @@ }, "jumpToBlock": { "items": { - "type": "string" + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ] }, "type": "array", "default": [