From d23fe24100a4811e57a596833115493465e53965 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 18 Jun 2026 09:20:13 +0200 Subject: [PATCH] Extract diffSplitState from the files diff renderer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The files diff renderer decides, from the selected file's staged/unstaged status and the splitDiff config, whether the focused main view is split into unstaged/staged halves and — when not split — whether the single view shows the staged diff. A second consumer is about to need the same decision (staging a line directly from the focused main view must know whether the shown diff is staged or unstaged, to pick apply vs apply --reverse). Pull it into a method so the two can't drift from each other. Co-Authored-By: Claude Opus 4.8 --- pkg/gui/controllers/files_controller.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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.