From 130480555f1242a7b866f32a5ef1cb2f9a2504a4 Mon Sep 17 00:00:00 2001 From: Davyd McColl Date: Fri, 11 Jun 2021 15:19:15 +0200 Subject: [PATCH] :sparkles: always show whitespace in diffs when entering line-by-line staging --- pkg/gui/staging_panel.go | 4 ++++ pkg/gui/whitespace-toggle.go | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 916361fc1..f30aadd6a 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -33,6 +33,10 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx gui.Views.Secondary.Title = gui.Tr.StagedChanges } + // if we were ignoring whitespace, stop doing that so that + // line-by-line diffs work as expected + gui.setIgnoreWhitespaceFlag(false) + // note for custom diffs, we'll need to send a flag here saying not to use the custom diff diff := gui.GitCommand.WorktreeFileDiff(file, true, secondaryFocused, gui.State.IgnoreWhitespaceInDiffView) secondaryDiff := gui.GitCommand.WorktreeFileDiff(file, true, !secondaryFocused, gui.State.IgnoreWhitespaceInDiffView) diff --git a/pkg/gui/whitespace-toggle.go b/pkg/gui/whitespace-toggle.go index e7df9d879..697770a94 100644 --- a/pkg/gui/whitespace-toggle.go +++ b/pkg/gui/whitespace-toggle.go @@ -1,7 +1,15 @@ package gui func (gui *Gui) toggleWhitespaceInDiffView() error { - gui.State.IgnoreWhitespaceInDiffView = !gui.State.IgnoreWhitespaceInDiffView + return gui.setIgnoreWhitespaceFlag(!gui.State.IgnoreWhitespaceInDiffView) +} + +func (gui *Gui) setIgnoreWhitespaceFlag(shouldIgnoreWhitespace bool) error { + if gui.State.IgnoreWhitespaceInDiffView == shouldIgnoreWhitespace { + return nil + } + + gui.State.IgnoreWhitespaceInDiffView = shouldIgnoreWhitespace toastMessage := gui.Tr.ShowingWhitespaceInDiffView if gui.State.IgnoreWhitespaceInDiffView {