mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Extract diffSplitState from the files diff renderer
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 <noreply@anthropic.com>
This commit is contained in:
parent
9bb070be76
commit
d23fe24100
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue