diff options
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r-- | pkg/gui/keybindings.go | 653 |
1 files changed, 322 insertions, 331 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c0d9fc52c..f1283617a 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -592,9 +592,8 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { // GetCurrentKeybindings gets the list of keybindings given the current context func (gui *Gui) GetCurrentKeybindings() []*Binding { bindings := gui.GetInitialKeybindings() - viewName := gui.currentViewName() - currentContext := gui.State.Contexts[viewName] - contextBindings := gui.GetContextMap()[viewName][currentContext] + currentContext := gui.State.Context + contextBindings := gui.GetContextMap()[currentContext] return append(bindings, contextBindings...) } @@ -607,347 +606,339 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { return err } } - if err := gui.setInitialContexts(); err != nil { + if err := gui.setInitialContext(); err != nil { return err } return nil } -func (gui *Gui) GetContextMap() map[string]map[string][]*Binding { - return map[string]map[string][]*Binding{ - "secondary": { - "normal": { - { - ViewName: "secondary", - Key: gocui.MouseLeft, - Modifier: gocui.ModNone, - Handler: gui.handleMouseDownSecondary, - }, +func (gui *Gui) GetContextMap() map[string][]*Binding { + return map[string][]*Binding{ + "normal": { + { + ViewName: "secondary", + Key: gocui.MouseLeft, + Modifier: gocui.ModNone, + Handler: gui.handleMouseDownSecondary, }, - "staging": { - { - ViewName: "secondary", - Key: gocui.MouseLeft, - Modifier: gocui.ModNone, - Handler: gui.handleTogglePanelClick, - }, + { + ViewName: "main", + Key: gocui.MouseWheelDown, + Modifier: gocui.ModNone, + Handler: gui.scrollDownMain, + Description: gui.Tr.SLocalize("ScrollDown"), + Alternative: "fn+up", + }, { + ViewName: "main", + Key: gocui.MouseWheelUp, + Modifier: gocui.ModNone, + Handler: gui.scrollUpMain, + Description: gui.Tr.SLocalize("ScrollUp"), + Alternative: "fn+down", + }, { + ViewName: "main", + Key: gocui.MouseLeft, + Modifier: gocui.ModNone, + Handler: gui.handleMouseDownMain, }, }, - "main": { - "normal": { - { - ViewName: "main", - Key: gocui.MouseWheelDown, - Modifier: gocui.ModNone, - Handler: gui.scrollDownMain, - Description: gui.Tr.SLocalize("ScrollDown"), - Alternative: "fn+up", - }, { - ViewName: "main", - Key: gocui.MouseWheelUp, - Modifier: gocui.ModNone, - Handler: gui.scrollUpMain, - Description: gui.Tr.SLocalize("ScrollUp"), - Alternative: "fn+down", - }, { - ViewName: "main", - Key: gocui.MouseLeft, - Modifier: gocui.ModNone, - Handler: gui.handleMouseDownMain, - }, + "staging": { + { + ViewName: "secondary", + Key: gocui.MouseLeft, + Modifier: gocui.ModNone, + Handler: gui.handleTogglePanelClick, }, - "staging": { - { - ViewName: "main", - Key: gocui.KeyEsc, - Modifier: gocui.ModNone, - Handler: gui.handleStagingEscape, - Description: gui.Tr.SLocalize("ReturnToFilesPanel"), - }, { - ViewName: "main", - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevLine, - Description: gui.Tr.SLocalize("PrevLine"), - }, { - ViewName: "main", - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextLine, - Description: gui.Tr.SLocalize("NextLine"), - }, { - ViewName: "main", - Key: 'k', - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevLine, - }, { - ViewName: "main", - Key: 'j', - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextLine, - }, { - ViewName: "main", - Key: gocui.KeyArrowLeft, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevHunk, - Description: gui.Tr.SLocalize("PrevHunk"), - }, { - ViewName: "main", - Key: gocui.KeyArrowRight, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextHunk, - Description: gui.Tr.SLocalize("NextHunk"), - }, { - ViewName: "main", - Key: 'h', - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevHunk, - }, { - ViewName: "main", - Key: 'l', - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextHunk, - }, { - ViewName: "main", - Key: gocui.KeySpace, - Modifier: gocui.ModNone, - Handler: gui.handleStageSelection, - Description: gui.Tr.SLocalize("StageSelection"), - }, { - ViewName: "main", - Key: 'd', - Modifier: gocui.ModNone, - Handler: gui.handleResetSelection, - Description: gui.Tr.SLocalize("ResetSelection"), - }, { - ViewName: "main", - Key: 'v', - Modifier: gocui.ModNone, - Handler: gui.handleToggleSelectRange, - Description: gui.Tr.SLocalize("ToggleDragSelect"), - }, { - ViewName: "main", - Key: 'a', - Modifier: gocui.ModNone, - Handler: gui.handleToggleSelectHunk, - Description: gui.Tr.SLocalize("ToggleSelectHunk"), - }, { - ViewName: "main", - Key: gocui.KeyTab, - Modifier: gocui.ModNone, - Handler: gui.handleTogglePanel, - Description: gui.Tr.SLocalize("TogglePanel"), - }, { - ViewName: "main", - Key: gocui.MouseLeft, - Modifier: gocui.ModNone, - Handler: gui.handleMouseDown, - }, { - ViewName: "main", - Key: gocui.MouseLeft, - Modifier: gocui.ModMotion, - Handler: gui.handleMouseDrag, - }, { - ViewName: "main", - Key: gocui.MouseWheelUp, - Modifier: gocui.ModNone, - Handler: gui.handleMouseScrollUp, - }, { - ViewName: "main", - Key: gocui.MouseWheelDown, - Modifier: gocui.ModNone, - Handler: gui.handleMouseScrollDown, - }, + { + ViewName: "main", + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.handleStagingEscape, + Description: gui.Tr.SLocalize("ReturnToFilesPanel"), + }, { + ViewName: "main", + Key: gocui.KeyArrowUp, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevLine, + Description: gui.Tr.SLocalize("PrevLine"), + }, { + ViewName: "main", + Key: gocui.KeyArrowDown, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextLine, + Description: gui.Tr.SLocalize("NextLine"), + }, { + ViewName: "main", + Key: 'k', + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevLine, + }, { + ViewName: "main", + Key: 'j', + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextLine, + }, { + ViewName: "main", + Key: gocui.KeyArrowLeft, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevHunk, + Description: gui.Tr.SLocalize("PrevHunk"), + }, { + ViewName: "main", + Key: gocui.KeyArrowRight, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextHunk, + Description: gui.Tr.SLocalize("NextHunk"), + }, { + ViewName: "main", + Key: 'h', + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevHunk, + }, { + ViewName: "main", + Key: 'l', + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextHunk, + }, { + ViewName: "main", + Key: gocui.KeySpace, + Modifier: gocui.ModNone, + Handler: gui.handleStageSelection, + Description: gui.Tr.SLocalize("StageSelection"), + }, { + ViewName: "main", + Key: 'd', + Modifier: gocui.ModNone, + Handler: gui.handleResetSelection, + Description: gui.Tr.SLocalize("ResetSelection"), + }, { + ViewName: "main", + Key: 'v', + Modifier: gocui.ModNone, + Handler: gui.handleToggleSelectRange, + Description: gui.Tr.SLocalize("ToggleDragSelect"), + }, { + ViewName: "main", + Key: 'a', + Modifier: gocui.ModNone, + Handler: gui.handleToggleSelectHunk, + Description: gui.Tr.SLocalize("ToggleSelectHunk"), + }, { + ViewName: "main", + Key: gocui.KeyTab, + Modifier: gocui.ModNone, + Handler: gui.handleTogglePanel, + Description: gui.Tr.SLocalize("TogglePanel"), + }, { + ViewName: "main", + Key: gocui.MouseLeft, + Modifier: gocui.ModNone, + Handler: gui.handleMouseDown, + }, { + ViewName: "main", + Key: gocui.MouseLeft, + Modifier: gocui.ModMotion, + Handler: gui.handleMouseDrag, + }, { + ViewName: "main", + Key: gocui.MouseWheelUp, + Modifier: gocui.ModNone, + Handler: gui.handleMouseScrollUp, + }, { + ViewName: "main", + Key: gocui.MouseWheelDown, + Modifier: gocui.ModNone, + Handler: gui.handleMouseScrollDown, }, - "patch-building": { - { - ViewName: "main", - Key: gocui.KeyEsc, - Modifier: gocui.ModNone, - Handler: gui.handleEscapePatchBuildingPanel, - Description: gui.Tr.SLocalize("ExitLineByLineMode"), - }, { - ViewName: "main", - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevLine, - Description: gui.Tr.SLocalize("PrevLine"), - }, { - ViewName: "main", - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextLine, - Description: gui.Tr.SLocalize("NextLine"), - }, { - ViewName: "main", - Key: 'k', - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevLine, - }, { - ViewName: "main", - Key: 'j', - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextLine, - }, { - ViewName: "main", - Key: gocui.MouseWheelUp, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevLine, - }, { - ViewName: "main", - Key: gocui.MouseWheelDown, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextLine, - }, { - ViewName: "main", - Key: gocui.KeyArrowLeft, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevHunk, - Description: gui.Tr.SLocalize("PrevHunk"), - }, { - ViewName: "main", - Key: gocui.KeyArrowRight, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextHunk, - Description: gui.Tr.SLocalize("NextHunk"), - }, { - ViewName: "main", - Key: 'h', - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevHunk, - }, { - ViewName: "main", - Key: 'l', - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextHunk, - }, { - ViewName: "main", - Key: gocui.KeySpace, - Modifier: gocui.ModNone, - Handler: gui.handleAddSelectionToPatch, - Description: gui.Tr.SLocalize("StageSelection"), - }, { - ViewName: "main", - Key: 'd', - Modifier: gocui.ModNone, - Handler: gui.handleRemoveSelectionFromPatch, - Description: gui.Tr.SLocalize("ResetSelection"), - }, { - ViewName: "main", - Key: 'v', - Modifier: gocui.ModNone, - Handler: gui.handleToggleSelectRange, - Description: gui.Tr.SLocalize("ToggleDragSelect"), - }, { - ViewName: "main", - Key: 'a', - Modifier: gocui.ModNone, - Handler: gui.handleToggleSelectHunk, - Description: gui.Tr.SLocalize("ToggleSelectHunk"), - }, { - ViewName: "main", - Key: gocui.MouseLeft, - Modifier: gocui.ModNone, - Handler: gui.handleMouseDown, - }, { - ViewName: "main", - Key: gocui.MouseLeft, - Modifier: gocui.ModMotion, - Handler: gui.handleMouseDrag, - }, { - ViewName: "main", - Key: gocui.MouseWheelUp, - Modifier: gocui.ModNone, - Handler: gui.handleMouseScrollUp, - }, { - ViewName: "main", - Key: gocui.MouseWheelDown, - Modifier: gocui.ModNone, - Handler: gui.handleMouseScrollDown, - }, + }, + "patch-building": { + { + ViewName: "main", + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.handleEscapePatchBuildingPanel, + Description: gui.Tr.SLocalize("ExitLineByLineMode"), + }, { + ViewName: "main", + Key: gocui.KeyArrowUp, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevLine, + Description: gui.Tr.SLocalize("PrevLine"), + }, { + ViewName: "main", + Key: gocui.KeyArrowDown, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextLine, + Description: gui.Tr.SLocalize("NextLine"), + }, { + ViewName: "main", + Key: 'k', + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevLine, + }, { + ViewName: "main", + Key: 'j', + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextLine, + }, { + ViewName: "main", + Key: gocui.MouseWheelUp, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevLine, + }, { + ViewName: "main", + Key: gocui.MouseWheelDown, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextLine, + }, { + ViewName: "main", + Key: gocui.KeyArrowLeft, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevHunk, + Description: gui.Tr.SLocalize("PrevHunk"), + }, { + ViewName: "main", + Key: gocui.KeyArrowRight, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextHunk, + Description: gui.Tr.SLocalize("NextHunk"), + }, { + ViewName: "main", + Key: 'h', + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevHunk, + }, { + ViewName: "main", + Key: 'l', + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextHunk, + }, { + ViewName: "main", + Key: gocui.KeySpace, + Modifier: gocui.ModNone, + Handler: gui.handleAddSelectionToPatch, + Description: gui.Tr.SLocalize("StageSelection"), + }, { + ViewName: "main", + Key: 'd', + Modifier: gocui.ModNone, + Handler: gui.handleRemoveSelectionFromPatch, + Description: gui.Tr.SLocalize("ResetSelection"), + }, { + ViewName: "main", + Key: 'v', + Modifier: gocui.ModNone, + Handler: gui.handleToggleSelectRange, + Description: gui.Tr.SLocalize("ToggleDragSelect"), + }, { + ViewName: "main", + Key: 'a', + Modifier: gocui.ModNone, + Handler: gui.handleToggleSelectHunk, + Description: gui.Tr.SLocalize("ToggleSelectHunk"), + }, { + ViewName: "main", + Key: gocui.MouseLeft, + Modifier: gocui.ModNone, + Handler: gui.handleMouseDown, + }, { + ViewName: "main", + Key: gocui.MouseLeft, + Modifier: gocui.ModMotion, + Handler: gui.handleMouseDrag, + }, { + ViewName: "main", + Key: gocui.MouseWheelUp, + Modifier: gocui.ModNone, + Handler: gui.handleMouseScrollUp, + }, { + ViewName: "main", + Key: gocui.MouseWheelDown, + Modifier: gocui.ModNone, + Handler: gui.handleMouseScrollDown, }, - "merging": { - { - ViewName: "main", - Key: gocui.KeyEsc, - Modifier: gocui.ModNone, - Handler: gui.handleEscapeMerge, - Description: gui.Tr.SLocalize("ReturnToFilesPanel"), - }, { - ViewName: "main", - Key: gocui.KeySpace, - Modifier: gocui.ModNone, - Handler: gui.handlePickHunk, - Description: gui.Tr.SLocalize("PickHunk"), - }, { - ViewName: "main", - Key: 'b', - Modifier: gocui.ModNone, - Handler: gui.handlePickBothHunks, - Description: gui.Tr.SLocalize("PickBothHunks"), - }, { - ViewName: "main", - Key: gocui.KeyArrowLeft, - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevConflict, - Description: gui.Tr.SLocalize("PrevConflict"), - }, { - ViewName: "main", - Key: gocui.KeyArrowRight, - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextConflict, + }, + "merging": { + { + ViewName: "main", + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.handleEscapeMerge, + Description: gui.Tr.SLocalize("ReturnToFilesPanel"), + }, { + ViewName: "main", + Key: gocui.KeySpace, + Modifier: gocui.ModNone, + Handler: gui.handlePickHunk, + Description: gui.Tr.SLocalize("PickHunk"), + }, { + ViewName: "main", + Key: 'b', + Modifier: gocui.ModNone, + Handler: gui.handlePickBothHunks, + Description: gui.Tr.SLocalize("PickBothHunks"), + }, { + ViewName: "main", + Key: gocui.KeyArrowLeft, + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevConflict, + Description: gui.Tr.SLocalize("PrevConflict"), + }, { + ViewName: "main", + Key: gocui.KeyArrowRight, + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextConflict, - Description: gui.Tr.SLocalize("NextConflict"), - }, { - ViewName: "main", - Key: gocui.KeyArrowUp, + Description: gui.Tr.SLocalize("NextConflict"), + }, { + ViewName: "main", + Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - Handler: gui.handleSelectTop, - Description: gui.Tr.SLocalize("SelectTop"), - }, { - ViewName: "main", - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - Handler: gui.handleSelectBottom, - Description: gui.Tr.SLocalize("SelectBottom"), - }, { - ViewName: "main", - Key: gocui.MouseWheelUp, - Modifier: gocui.ModNone, - Handler: gui.handleSelectTop, - }, { - ViewName: "main", - Key: gocui.MouseWheelDown, - Modifier: gocui.ModNone, - Handler: gui.handleSelectBottom, - }, { - ViewName: "main", - Key: 'h', - Modifier: gocui.ModNone, - Handler: gui.handleSelectPrevConflict, - }, { - ViewName: "main", - Key: 'l', - Modifier: gocui.ModNone, - Handler: gui.handleSelectNextConflict, - }, { - ViewName: "main", - Key: 'k', - Modifier: gocui.ModNone, - Handler: gui.handleSelectTop, - }, { - ViewName: "main", - Key: 'j', - Modifier: gocui.ModNone, - Handler: gui.handleSelectBottom, - }, { - ViewName: "main", - Key: 'z', - Modifier: gocui.ModNone, - Handler: gui.handlePopFileSnapshot, - Description: gui.Tr.SLocalize("Undo"), - }, + Modifier: gocui.ModNone, + Handler: gui.handleSelectTop, + Description: gui.Tr.SLocalize("SelectTop"), + }, { + ViewName: "main", + Key: gocui.KeyArrowDown, + Modifier: gocui.ModNone, + Handler: gui.handleSelectBottom, + Description: gui.Tr.SLocalize("SelectBottom"), + }, { + ViewName: "main", + Key: gocui.MouseWheelUp, + Modifier: gocui.ModNone, + Handler: gui.handleSelectTop, + }, { + ViewName: "main", + Key: gocui.MouseWheelDown, + Modifier: gocui.ModNone, + Handler: gui.handleSelectBottom, + }, { + ViewName: "main", + Key: 'h', + Modifier: gocui.ModNone, + Handler: gui.handleSelectPrevConflict, + }, { + ViewName: "main", + Key: 'l', + Modifier: gocui.ModNone, + Handler: gui.handleSelectNextConflict, + }, { + ViewName: "main", + Key: 'k', + Modifier: gocui.ModNone, + Handler: gui.handleSelectTop, + }, { + ViewName: "main", + Key: 'j', + Modifier: gocui.ModNone, + Handler: gui.handleSelectBottom, + }, { + ViewName: "main", + Key: 'z', + Modifier: gocui.ModNone, + Handler: gui.handlePopFileSnapshot, + Description: gui.Tr.SLocalize("Undo"), }, }, } |