1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Improve JumpToBlock keybinding functionality

Improve experience when yaml file has != 5 keybindings and change view
helper to use the length of the array instead of hardcoded value.
This commit is contained in:
Sam Burville
2021-10-17 18:22:59 +01:00
committed by Jesse Duffield
parent 91e8765d9c
commit f6e316dfe5
4 changed files with 73 additions and 69 deletions

View File

@ -101,7 +101,7 @@ keybinding:
nextBlock: '<right>' # goto the next block / panel
prevBlock-alt: 'h' # goto the previous block / panel
nextBlock-alt: 'l' # goto the next block / panel
jumpToBlock: "1", "2", "3", "4", "5" # goto the Nth block / panel
jumpToBlock: ["1", "2", "3", "4", "5"] # goto the Nth block / panel
nextMatch: 'n'
prevMatch: 'N'
optionMenu: 'x' # show help menu

View File

@ -125,7 +125,7 @@ type KeybindingUniversalConfig struct {
NextBlockAlt string `yaml:"nextBlock-alt"`
NextBlockAlt2 string `yaml:"nextBlock-alt2"`
PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
JumpToBlock [5]string `yaml:"JumpToBlock"`
JumpToBlock []string `yaml:"jumpToBlock"`
NextMatch string `yaml:"nextMatch"`
PrevMatch string `yaml:"prevMatch"`
StartSearch string `yaml:"startSearch"`
@ -378,7 +378,7 @@ func GetDefaultConfig() *UserConfig {
NextBlockAlt: "l",
PrevBlockAlt2: "<backtab>",
NextBlockAlt2: "<tab>",
JumpToBlock: [5]string{"1", "2", "3", "4", "5"},
JumpToBlock: []string{"1", "2", "3", "4", "5"},
NextMatch: "n",
PrevMatch: "N",
StartSearch: "/",

View File

@ -1818,6 +1818,9 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
}
// Appends keybindings to jump to a particular sideView using numbers
if len(config.Universal.JumpToBlock) != 5 {
log.Fatal("Jump to block keybindings cannot be set. Exactly 5 keybindings must be supplied.")
} else {
for i, window := range []string{"status", "files", "branches", "commits", "stash"} {
bindings = append(bindings, &Binding{
ViewName: "",
@ -1825,6 +1828,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone,
Handler: gui.goToSideWindow(window)})
}
}
for viewName := range gui.State.Contexts.initialViewTabContextMap() {
bindings = append(bindings, []*Binding{

View File

@ -322,7 +322,7 @@ func (gui *Gui) globalOptionsMap() map[string]string {
gui.getKeyDisplay(keybindingConfig.Universal.Return): gui.Tr.LcCancel,
gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.Tr.LcQuit,
gui.getKeyDisplay(keybindingConfig.Universal.OptionMenu): gui.Tr.LcMenu,
fmt.Sprintf("%s-%s", gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[0]), gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[4])): gui.Tr.LcJump,
fmt.Sprintf("%s-%s", gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[0]), gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])): gui.Tr.LcJump,
}
}