diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index 49311b6d4..13148a3c6 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -10,7 +10,7 @@ func (gui *Gui) mainSectionChildren() []*boxlayout.Box { // if we're not in split mode we can just show the one main panel. Likewise if // the main panel is focused and we're in full-screen mode - if !gui.State.SplitMainPanel || (gui.State.ScreenMode == SCREEN_FULL && currentViewName == "main") { + if !gui.isMainPanelSplit() || (gui.State.ScreenMode == SCREEN_FULL && currentViewName == "main") { return []*boxlayout.Box{ { ViewName: "main", @@ -47,7 +47,7 @@ func (gui *Gui) getMidSectionWeights() (int, int) { mainSectionWeight := int(1/sidePanelWidthRatio) - 1 sideSectionWeight := 1 - if gui.State.SplitMainPanel { + if gui.isMainPanelSplit() { mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side } diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index c18f97253..1cb1ba5fa 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -26,7 +26,7 @@ func (gui *Gui) handleBranchSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Log" diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 435215f21..7418cf3aa 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -19,7 +19,7 @@ func (gui *Gui) exitDiffMode() error { func (gui *Gui) renderDiff() error { gui.getMainView().Title = "Diff" - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) filterArg := "" if gui.inFilterMode() { filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 62c2e7cbe..45eee06e4 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -37,7 +37,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { file := gui.getSelectedFile() if file == nil { - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "" return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles")) } @@ -53,12 +53,12 @@ func (gui *Gui) selectFile(alreadySelected bool) error { if file.HasInlineMergeConflicts { gui.getMainView().Title = gui.Tr.SLocalize("MergeConflictsTitle") - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) return gui.refreshMergePanel() } if file.HasStagedChanges && file.HasUnstagedChanges { - gui.State.SplitMainPanel = true + gui.splitMainPanel(true) gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges") gui.getSecondaryView().Title = gui.Tr.SLocalize("StagedChanges") cmdStr := gui.GitCommand.DiffCmdStr(file, false, true) @@ -67,7 +67,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { return err } } else { - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) if file.HasUnstagedChanges { gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges") } else { diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index 6bd8949d2..67caba0ae 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -10,7 +10,7 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { return gui.handleEscapePatchBuildingPanel() } - gui.State.SplitMainPanel = true + gui.splitMainPanel(true) gui.getMainView().Title = "Patch" gui.getSecondaryView().Title = "Custom Patch" @@ -80,7 +80,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error { if gui.GitCommand.PatchManager.IsEmpty() { gui.GitCommand.PatchManager.Reset() - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) } return gui.switchContext(gui.Contexts.BranchCommits.Files.Context) @@ -88,7 +88,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error { func (gui *Gui) refreshSecondaryPatchPanel() error { if gui.GitCommand.PatchManager.CommitSelected() { - gui.State.SplitMainPanel = true + gui.splitMainPanel(true) secondaryView := gui.getSecondaryView() secondaryView.Highlight = true secondaryView.Wrap = false @@ -98,7 +98,7 @@ func (gui *Gui) refreshSecondaryPatchPanel() error { return nil }) } else { - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) } return nil diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index 107c8ac60..038e2bf7e 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -23,7 +23,7 @@ func (gui *Gui) handleReflogCommitSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Reflog Entry" diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 2f95f6d7a..29531c33f 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -24,7 +24,7 @@ func (gui *Gui) handleRemoteBranchSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Remote Branch" diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 4fdac65aa..8692cdd6b 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -27,7 +27,7 @@ func (gui *Gui) handleRemoteSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Remote" diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 47a63f40f..4c8cb3571 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -8,17 +8,10 @@ import ( ) func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx int) error { - gui.State.SplitMainPanel = true + gui.splitMainPanel(true) state := gui.State.Panels.LineByLine - // // We need to force focus here because the confirmation panel for safely staging lines does not return focus automatically. - // // This is because if we tell it to return focus it will unconditionally return it to the main panel which may not be what we want - // // e.g. in the event that there's nothing left to stage. - // if err := gui.switchContext(nil, gui.getMainView()); err != nil { - // return err - // } - file := gui.getSelectedFile() if file == nil { return gui.handleStagingEscape() diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index a818d650b..ec2c4ba8e 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -22,7 +22,7 @@ func (gui *Gui) handleStashEntrySelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Stash" diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index 78569768e..e01d8d41b 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -93,7 +93,7 @@ func (gui *Gui) handleStatusSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "" diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index e31a8f8c3..cd50e34eb 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -22,7 +22,7 @@ func (gui *Gui) handleTagSelect() error { return nil } - gui.State.SplitMainPanel = false + gui.splitMainPanel(false) gui.getMainView().Title = "Tag" diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index df3dc5ece..137e0e96f 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -368,3 +368,16 @@ func (gui *Gui) clearEditorView(v *gocui.View) { _ = v.SetCursor(0, 0) _ = v.SetOrigin(0, 0) } + +func (gui *Gui) splitMainPanel(state bool) { + gui.State.SplitMainPanel = state + + // no need to set view on bottom when state is false: it will have zero size anyway thanks to our view arrangement code. + if state { + _, _ = gui.g.SetViewOnTop("secondary") + } +} + +func (gui *Gui) isMainPanelSplit() bool { + return gui.State.SplitMainPanel +}