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 nextBlock: '<right>' # goto the next block / panel
prevBlock-alt: 'h' # goto the previous block / panel prevBlock-alt: 'h' # goto the previous block / panel
nextBlock-alt: 'l' # goto the next 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' nextMatch: 'n'
prevMatch: 'N' prevMatch: 'N'
optionMenu: 'x' # show help menu optionMenu: 'x' # show help menu

View File

@ -106,66 +106,66 @@ type KeybindingConfig struct {
// damn looks like we have some inconsistencies here with -alt and -alt1 // damn looks like we have some inconsistencies here with -alt and -alt1
type KeybindingUniversalConfig struct { type KeybindingUniversalConfig struct {
Quit string `yaml:"quit"` Quit string `yaml:"quit"`
QuitAlt1 string `yaml:"quit-alt1"` QuitAlt1 string `yaml:"quit-alt1"`
Return string `yaml:"return"` Return string `yaml:"return"`
QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"` QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"`
TogglePanel string `yaml:"togglePanel"` TogglePanel string `yaml:"togglePanel"`
PrevItem string `yaml:"prevItem"` PrevItem string `yaml:"prevItem"`
NextItem string `yaml:"nextItem"` NextItem string `yaml:"nextItem"`
PrevItemAlt string `yaml:"prevItem-alt"` PrevItemAlt string `yaml:"prevItem-alt"`
NextItemAlt string `yaml:"nextItem-alt"` NextItemAlt string `yaml:"nextItem-alt"`
PrevPage string `yaml:"prevPage"` PrevPage string `yaml:"prevPage"`
NextPage string `yaml:"nextPage"` NextPage string `yaml:"nextPage"`
GotoTop string `yaml:"gotoTop"` GotoTop string `yaml:"gotoTop"`
GotoBottom string `yaml:"gotoBottom"` GotoBottom string `yaml:"gotoBottom"`
PrevBlock string `yaml:"prevBlock"` PrevBlock string `yaml:"prevBlock"`
NextBlock string `yaml:"nextBlock"` NextBlock string `yaml:"nextBlock"`
PrevBlockAlt string `yaml:"prevBlock-alt"` PrevBlockAlt string `yaml:"prevBlock-alt"`
NextBlockAlt string `yaml:"nextBlock-alt"` NextBlockAlt string `yaml:"nextBlock-alt"`
NextBlockAlt2 string `yaml:"nextBlock-alt2"` NextBlockAlt2 string `yaml:"nextBlock-alt2"`
PrevBlockAlt2 string `yaml:"prevBlock-alt2"` PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
JumpToBlock [5]string `yaml:"JumpToBlock"` JumpToBlock []string `yaml:"jumpToBlock"`
NextMatch string `yaml:"nextMatch"` NextMatch string `yaml:"nextMatch"`
PrevMatch string `yaml:"prevMatch"` PrevMatch string `yaml:"prevMatch"`
StartSearch string `yaml:"startSearch"` StartSearch string `yaml:"startSearch"`
OptionMenu string `yaml:"optionMenu"` OptionMenu string `yaml:"optionMenu"`
OptionMenuAlt1 string `yaml:"optionMenu-alt1"` OptionMenuAlt1 string `yaml:"optionMenu-alt1"`
Select string `yaml:"select"` Select string `yaml:"select"`
GoInto string `yaml:"goInto"` GoInto string `yaml:"goInto"`
Confirm string `yaml:"confirm"` Confirm string `yaml:"confirm"`
ConfirmAlt1 string `yaml:"confirm-alt1"` ConfirmAlt1 string `yaml:"confirm-alt1"`
Remove string `yaml:"remove"` Remove string `yaml:"remove"`
New string `yaml:"new"` New string `yaml:"new"`
Edit string `yaml:"edit"` Edit string `yaml:"edit"`
OpenFile string `yaml:"openFile"` OpenFile string `yaml:"openFile"`
ScrollUpMain string `yaml:"scrollUpMain"` ScrollUpMain string `yaml:"scrollUpMain"`
ScrollDownMain string `yaml:"scrollDownMain"` ScrollDownMain string `yaml:"scrollDownMain"`
ScrollUpMainAlt1 string `yaml:"scrollUpMain-alt1"` ScrollUpMainAlt1 string `yaml:"scrollUpMain-alt1"`
ScrollDownMainAlt1 string `yaml:"scrollDownMain-alt1"` ScrollDownMainAlt1 string `yaml:"scrollDownMain-alt1"`
ScrollUpMainAlt2 string `yaml:"scrollUpMain-alt2"` ScrollUpMainAlt2 string `yaml:"scrollUpMain-alt2"`
ScrollDownMainAlt2 string `yaml:"scrollDownMain-alt2"` ScrollDownMainAlt2 string `yaml:"scrollDownMain-alt2"`
ExecuteCustomCommand string `yaml:"executeCustomCommand"` ExecuteCustomCommand string `yaml:"executeCustomCommand"`
CreateRebaseOptionsMenu string `yaml:"createRebaseOptionsMenu"` CreateRebaseOptionsMenu string `yaml:"createRebaseOptionsMenu"`
PushFiles string `yaml:"pushFiles"` PushFiles string `yaml:"pushFiles"`
PullFiles string `yaml:"pullFiles"` PullFiles string `yaml:"pullFiles"`
Refresh string `yaml:"refresh"` Refresh string `yaml:"refresh"`
CreatePatchOptionsMenu string `yaml:"createPatchOptionsMenu"` CreatePatchOptionsMenu string `yaml:"createPatchOptionsMenu"`
NextTab string `yaml:"nextTab"` NextTab string `yaml:"nextTab"`
PrevTab string `yaml:"prevTab"` PrevTab string `yaml:"prevTab"`
NextScreenMode string `yaml:"nextScreenMode"` NextScreenMode string `yaml:"nextScreenMode"`
PrevScreenMode string `yaml:"prevScreenMode"` PrevScreenMode string `yaml:"prevScreenMode"`
Undo string `yaml:"undo"` Undo string `yaml:"undo"`
Redo string `yaml:"redo"` Redo string `yaml:"redo"`
FilteringMenu string `yaml:"filteringMenu"` FilteringMenu string `yaml:"filteringMenu"`
DiffingMenu string `yaml:"diffingMenu"` DiffingMenu string `yaml:"diffingMenu"`
DiffingMenuAlt string `yaml:"diffingMenu-alt"` DiffingMenuAlt string `yaml:"diffingMenu-alt"`
CopyToClipboard string `yaml:"copyToClipboard"` CopyToClipboard string `yaml:"copyToClipboard"`
OpenRecentRepos string `yaml:"openRecentRepos"` OpenRecentRepos string `yaml:"openRecentRepos"`
SubmitEditorText string `yaml:"submitEditorText"` SubmitEditorText string `yaml:"submitEditorText"`
AppendNewline string `yaml:"appendNewline"` AppendNewline string `yaml:"appendNewline"`
ExtrasMenu string `yaml:"extrasMenu"` ExtrasMenu string `yaml:"extrasMenu"`
ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"`
} }
type KeybindingStatusConfig struct { type KeybindingStatusConfig struct {
@ -378,7 +378,7 @@ func GetDefaultConfig() *UserConfig {
NextBlockAlt: "l", NextBlockAlt: "l",
PrevBlockAlt2: "<backtab>", PrevBlockAlt2: "<backtab>",
NextBlockAlt2: "<tab>", NextBlockAlt2: "<tab>",
JumpToBlock: [5]string{"1", "2", "3", "4", "5"}, JumpToBlock: []string{"1", "2", "3", "4", "5"},
NextMatch: "n", NextMatch: "n",
PrevMatch: "N", PrevMatch: "N",
StartSearch: "/", StartSearch: "/",

View File

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

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.Return): gui.Tr.LcCancel,
gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.Tr.LcQuit, gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.Tr.LcQuit,
gui.getKeyDisplay(keybindingConfig.Universal.OptionMenu): gui.Tr.LcMenu, 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,
} }
} }