From 1ef585969fbbbf752af0db3a8ff688cda50a2f9f Mon Sep 17 00:00:00 2001 From: HiromasaNojima <67505578+HiromasaNojima@users.noreply.github.com> Date: Sun, 8 May 2022 17:24:55 +0900 Subject: [PATCH 1/2] add option to always show unstaged/staged panels --- docs/Config.md | 1 + pkg/config/user_config.go | 2 ++ pkg/gui/files_panel.go | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 44c6ace30..f8ab63362 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -54,6 +54,7 @@ gui: showCommandLog: true showIcons: false commandLogSize: 8 + splitDiff: 'auto' # one of 'auto' | 'always' git: paging: colorArg: always diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 900dd2e97..5c90f85a7 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -46,6 +46,7 @@ type GuiConfig struct { ShowBottomLine bool `yaml:"showBottomLine"` ShowIcons bool `yaml:"showIcons"` CommandLogSize int `yaml:"commandLogSize"` + SplitDiff string `yaml:"splitDiff"` } type ThemeConfig struct { @@ -360,6 +361,7 @@ func GetDefaultConfig() *UserConfig { ShowRandomTip: true, ShowIcons: false, CommandLogSize: 8, + SplitDiff: "auto", }, Git: GitConfig{ Paging: PagingConfig{ diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 765e33e4c..13d8e0470 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -67,7 +67,7 @@ func (gui *Gui) filesRenderToMain() error { }} if node.GetHasUnstagedChanges() { - if node.GetHasStagedChanges() { + if node.GetHasStagedChanges() || gui.c.UserConfig.Gui.SplitDiff == "always" { cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, true, gui.IgnoreWhitespaceInDiffView) refreshOpts.secondary = &viewUpdateOpts{ @@ -77,7 +77,19 @@ func (gui *Gui) filesRenderToMain() error { } } } else { - refreshOpts.main.title = gui.c.Tr.StagedChanges + if gui.c.UserConfig.Gui.SplitDiff == "auto" { + refreshOpts.main.title = gui.c.Tr.StagedChanges + } else { + cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, false, gui.IgnoreWhitespaceInDiffView) + refreshOpts.main.task = NewRunPtyTask(cmdObj.GetCmd()) + + cmdObj = gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, true, gui.IgnoreWhitespaceInDiffView) + refreshOpts.secondary = &viewUpdateOpts{ + title: gui.c.Tr.StagedChanges, + task: NewRunPtyTask(cmdObj.GetCmd()), + context: mainContext, + } + } } return gui.refreshMainViews(refreshOpts) From d72ffdc4a7034d0cc16880de4a6bdf308918ff13 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 15 May 2022 19:10:04 +1000 Subject: [PATCH 2/2] refactor --- pkg/gui/files_panel.go | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 13d8e0470..d4e156ccb 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -53,42 +53,31 @@ func (gui *Gui) filesRenderToMain() error { gui.resetMergeStateWithLock() - cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, !node.GetHasUnstagedChanges() && node.GetHasStagedChanges(), gui.IgnoreWhitespaceInDiffView) - mainContext := gui.State.Contexts.Normal if node.File != nil { mainContext = gui.State.Contexts.Staging } + split := gui.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) + mainShowsStaged := !split && node.GetHasStagedChanges() + + cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged, gui.IgnoreWhitespaceInDiffView) refreshOpts := refreshMainOpts{main: &viewUpdateOpts{ title: gui.c.Tr.UnstagedChanges, task: NewRunPtyTask(cmdObj.GetCmd()), context: mainContext, }} + if mainShowsStaged { + refreshOpts.main.title = gui.c.Tr.StagedChanges + } - if node.GetHasUnstagedChanges() { - if node.GetHasStagedChanges() || gui.c.UserConfig.Gui.SplitDiff == "always" { - cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, true, gui.IgnoreWhitespaceInDiffView) + if split { + cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, true, gui.IgnoreWhitespaceInDiffView) - refreshOpts.secondary = &viewUpdateOpts{ - title: gui.c.Tr.StagedChanges, - task: NewRunPtyTask(cmdObj.GetCmd()), - context: mainContext, - } - } - } else { - if gui.c.UserConfig.Gui.SplitDiff == "auto" { - refreshOpts.main.title = gui.c.Tr.StagedChanges - } else { - cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, false, gui.IgnoreWhitespaceInDiffView) - refreshOpts.main.task = NewRunPtyTask(cmdObj.GetCmd()) - - cmdObj = gui.git.WorkingTree.WorktreeFileDiffCmdObj(node, false, true, gui.IgnoreWhitespaceInDiffView) - refreshOpts.secondary = &viewUpdateOpts{ - title: gui.c.Tr.StagedChanges, - task: NewRunPtyTask(cmdObj.GetCmd()), - context: mainContext, - } + refreshOpts.secondary = &viewUpdateOpts{ + title: gui.c.Tr.StagedChanges, + task: NewRunPtyTask(cmdObj.GetCmd()), + context: mainContext, } }