diff options
-rw-r--r-- | pkg/gui/commit_files_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 3 | ||||
-rw-r--r-- | pkg/gui/context.go | 37 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 7 | ||||
-rw-r--r-- | pkg/gui/gui.go | 6 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 653 | ||||
-rw-r--r-- | pkg/gui/line_by_line_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/patch_building_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/patch_options_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 4 | ||||
-rw-r--r-- | scripts/generate_cheatsheet.go | 16 |
11 files changed, 363 insertions, 375 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index ab7b56ae7..9f7420075 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -29,6 +29,7 @@ func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error { } gui.getMainView().Title = "Patch" + gui.State.Panels.LineByLine = nil commitFile := gui.getSelectedCommitFile(g) if commitFile == nil { @@ -207,10 +208,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { } } - if err := gui.changeContext("main", "patch-building"); err != nil { - return err - } - if err := gui.changeContext("secondary", "patch-building"); err != nil { + if err := gui.changeContext("patch-building"); err != nil { return err } if err := gui.switchFocus(gui.g, gui.getCommitFilesView(), gui.getMainView()); err != nil { diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index ecc1a95ef..d46827598 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -47,6 +47,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { gui.getMainView().Title = "Patch" gui.getSecondaryView().Title = "Custom Patch" + gui.State.Panels.LineByLine = nil commit := gui.getSelectedCommit(g) if commit == nil { @@ -97,7 +98,7 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error { if g.CurrentView() == v { gui.handleCommitSelect(g, v) } - if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.Contexts["main"] == "patch-building") { + if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.Context == "patch-building") { return gui.refreshCommitFilesView() } return nil diff --git a/pkg/gui/context.go b/pkg/gui/context.go index fd8877ba0..be4b4dea9 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -1,42 +1,45 @@ package gui -func (gui *Gui) changeContext(viewName, context string) error { - if gui.State.Contexts[viewName] == context { +func (gui *Gui) changeContext(context string) error { + oldContext := gui.State.Context + + if gui.State.Context == context { return nil } contextMap := gui.GetContextMap() - gui.g.DeleteKeybindings(viewName) + oldBindings := contextMap[oldContext] + for _, binding := range oldBindings { + if err := gui.g.DeleteKeybinding(binding.ViewName, binding.Key, binding.Modifier); err != nil { + return err + } + } - bindings := contextMap[viewName][context] + bindings := contextMap[context] for _, binding := range bindings { if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil { return err } } - gui.State.Contexts[viewName] = context + + gui.State.Context = context return nil } -func (gui *Gui) setInitialContexts() error { +func (gui *Gui) setInitialContext() error { contextMap := gui.GetContextMap() - initialContexts := map[string]string{ - "main": "normal", - "secondary": "normal", - } + initialContext := "normal" - for viewName, context := range initialContexts { - bindings := contextMap[viewName][context] - for _, binding := range bindings { - if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil { - return err - } + bindings := contextMap[initialContext] + for _, binding := range bindings { + if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil { + return err } } - gui.State.Contexts = initialContexts + gui.State.Context = initialContext return nil } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 6b8847e8c..ba5c56db2 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -207,10 +207,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error if file.HasMergeConflicts { return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FileStagingRequirements")) } - if err := gui.changeContext("main", "staging"); err != nil { - return err - } - if err := gui.changeContext("secondary", "staging"); err != nil { + if err := gui.changeContext("staging"); err != nil { return err } if err := gui.switchFocus(gui.g, gui.getFilesView(), gui.getMainView()); err != nil { @@ -466,7 +463,7 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { if !file.HasInlineMergeConflicts { return gui.createErrorPanel(g, gui.Tr.SLocalize("FileNoMergeCons")) } - if err := gui.changeContext("main", "merging"); err != nil { + if err := gui.changeContext("merging"); err != nil { return err } if err := gui.switchFocus(g, v, gui.getMainView()); err != nil { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index b69b30965..1a0c88906 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -155,7 +155,7 @@ type guiState struct { Updating bool Panels *panelStates WorkingTreeState string // one of "merging", "rebasing", "normal" - Contexts map[string]string + Context string // important not to set this value directly but to use gui.changeContext("new context") CherryPickedCommits []*commands.Commit SplitMainPanel bool } @@ -281,11 +281,11 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error { } case "main": // if we have lost focus to a first-class panel, we need to do some cleanup - if err := gui.changeContext("main", "normal"); err != nil { + if err := gui.changeContext("normal"); err != nil { return err } case "commitFiles": - if gui.State.Contexts["main"] != "patch-building" { + if gui.State.Context != "patch-building" { if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil { return err } 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"), }, }, } diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 3ad105b0c..5aeaeeba2 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -226,7 +226,7 @@ func (gui *Gui) refreshMainView() error { var includedLineIndices []int // I'd prefer not to have knowledge of contexts using this file but I'm not sure // how to get around this - if gui.State.Contexts["main"] == "patch-building" { + if gui.State.Context == "patch-building" { filename := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name includedLineIndices = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename) } diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index a4b4de3eb..bc400cd24 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -88,7 +88,7 @@ func (gui *Gui) handleRemoveSelectionFromPatch(g *gocui.Gui, v *gocui.View) erro func (gui *Gui) handleEscapePatchBuildingPanel(g *gocui.Gui, v *gocui.View) error { gui.State.Panels.LineByLine = nil - gui.State.Contexts["main"] = "normal" + gui.changeContext("normal") if gui.GitCommand.PatchManager.IsEmpty() { gui.GitCommand.PatchManager.Reset() diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 52974bf8b..009faa83d 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -67,7 +67,7 @@ func (gui *Gui) validateNormalWorkingTreeState() (bool, error) { } func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error { - if gui.State.Contexts["main"] == "patch-building" { + if gui.State.Context == "patch-building" { return gui.handleEscapePatchBuildingPanel(gui.g, nil) } return nil diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 29180418c..ec1b3f647 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -117,7 +117,7 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error { case "credentials": return gui.handleCredentialsViewFocused(g, v) case "main": - if gui.State.Contexts["main"] == "merging" { + if gui.State.Context == "merging" { return gui.refreshMergePanel() } v.Hig |