mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Stop requiring jumpToBlock to have exactly five entries
The number of side panels is about to become configurable, so a fixed count of jump-to-panel keys no longer makes sense: a user who configures six panels shouldn't be forced to also extend jumpToBlock, and one who hides a panel shouldn't have to trim it. Drop the count check entirely (individual keys are still validated) and assign keys to panels positionally, for as many panels as there are keys. Surplus panels go without a jump key but remain reachable via the next/previous-panel keys. This also removes the log.Fatal that the count check guarded against. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
195b578fc1
commit
2f3ed7e0eb
|
|
@ -177,16 +177,7 @@ func validateKeybindingsRecurse(path string, node any) error {
|
|||
}
|
||||
|
||||
func validateKeybindings(keybindingConfig KeybindingConfig) error {
|
||||
if err := validateKeybindingsRecurse("", keybindingConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(keybindingConfig.Universal.JumpToBlock) != 5 {
|
||||
return fmt.Errorf("keybinding.universal.jumpToBlock must have 5 elements; found %d.",
|
||||
len(keybindingConfig.Universal.JumpToBlock))
|
||||
}
|
||||
|
||||
return nil
|
||||
return validateKeybindingsRecurse("", keybindingConfig)
|
||||
}
|
||||
|
||||
func validateCustomCommandKey(key Keybinding) error {
|
||||
|
|
|
|||
|
|
@ -134,11 +134,12 @@ func TestUserConfigValidate_enums(t *testing.T) {
|
|||
})
|
||||
},
|
||||
testCases: []testCase{
|
||||
{value: "", valid: false},
|
||||
{value: "1,2,3", valid: false},
|
||||
// The number of entries no longer has to match the number of side
|
||||
// panels, so only the validity of the individual keys matters.
|
||||
{value: "1,2,3", valid: true},
|
||||
{value: "1,2,3,4,5", valid: true},
|
||||
{value: "1,2,3,4,5,6", valid: true},
|
||||
{value: "1,2,3,4,invalid", valid: false},
|
||||
{value: "1,2,3,4,5,6", valid: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type JumpToSideWindowController struct {
|
||||
|
|
@ -30,19 +27,23 @@ func (self *JumpToSideWindowController) Context() types.Context {
|
|||
|
||||
func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
windows := self.c.Helpers().Window.SideWindows()
|
||||
jumpKeys := opts.Config.Universal.JumpToBlock
|
||||
|
||||
if len(opts.Config.Universal.JumpToBlock) != len(windows) {
|
||||
log.Fatal("Jump to block keybindings cannot be set. Exactly 5 keybindings must be supplied.")
|
||||
}
|
||||
|
||||
return lo.Map(windows, func(window string, index int) *types.Binding {
|
||||
return &types.Binding{
|
||||
// Assign jump keys to panels positionally (by default 1 to the first panel,
|
||||
// 2 to the second, etc.), for as many panels as there are keys. If there are
|
||||
// more panels than keys the extra panels just have no jump key, and if there
|
||||
// are more keys than panels the extra keys are unused; either way panels stay
|
||||
// reachable via the next/previous-panel keys.
|
||||
count := min(len(windows), len(jumpKeys))
|
||||
bindings := make([]*types.Binding, 0, count)
|
||||
for i := range count {
|
||||
bindings = append(bindings, &types.Binding{
|
||||
ViewName: "",
|
||||
// by default the keys are 1, 2, 3, etc
|
||||
Keys: opts.GetKeys(opts.Config.Universal.JumpToBlock[index]),
|
||||
Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(window)),
|
||||
}
|
||||
})
|
||||
Keys: opts.GetKeys(jumpKeys[i]),
|
||||
Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(windows[i])),
|
||||
})
|
||||
}
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *JumpToSideWindowController) goToSideWindow(window string) func() error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue