diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 0bd59ca16..2e448ae24 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -365,8 +365,7 @@ func (self *FilesController) renderNonTextualConflict(node *filetree.FileNode) { func (self *FilesController) renderWorkingTreeDiff(node *filetree.FileNode) { self.c.Helpers().MergeConflicts.ResetMergeState() - split := self.c.UserConfig().Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) - mainShowsStaged := !split && node.GetHasStagedChanges() + split, mainShowsStaged := self.diffSplitState(node) pathOverrides := self.pathOverridesForDiff(node) cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged, pathOverrides) @@ -445,6 +444,18 @@ func (self *FilesController) GetOnClickFocusedMainView() func(mainViewName strin } } +// diffSplitState reports, for the given file node, how the focused main view lays +// out its diff: whether it's split into unstaged (Normal) and staged +// (NormalSecondary) halves, and — when not split — whether the single Normal view +// shows the staged diff (which happens when the file has only staged changes). +// GetOnRenderToMain and GetOnStageFocusedMainView share this so the staging +// direction can't drift from what's on screen. +func (self *FilesController) diffSplitState(node *filetree.FileNode) (split bool, mainShowsStaged bool) { + split = self.c.UserConfig().Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) + mainShowsStaged = !split && node.GetHasStagedChanges() + return split, mainShowsStaged +} + // if we are dealing with a status for which there is no key in this map, // then we won't optimistically render: we'll just let `git status` tell // us what the new status is.