diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 572a87a73..54164e736 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -59,8 +59,19 @@ func (self *StashCommands) Sha(index int) (string, error) { return strings.Trim(sha, "\r\n"), err } -func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj { - cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", self.UserConfig.Git.Paging.ColorArg, self.UserConfig.Git.DiffContextSize, index) +func (self *StashCommands) ShowStashEntryCmdObj(index int, ignoreWhitespace bool) oscommands.ICmdObj { + ignoreWhitespaceFlag := "" + if ignoreWhitespace { + ignoreWhitespaceFlag = " --ignore-all-space" + } + + cmdStr := fmt.Sprintf( + "git stash show -p --stat --color=%s --unified=%d%s stash@{%d}", + self.UserConfig.Git.Paging.ColorArg, + self.UserConfig.Git.DiffContextSize, + ignoreWhitespaceFlag, + index, + ) return self.cmd.New(cmdStr).DontLog() } diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 1a4e50822..2fb03b90e 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -99,24 +99,34 @@ func TestStashSha(t *testing.T) { func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { - testName string - index int - contextSize int - expected string + testName string + index int + contextSize int + ignoreWhitespace bool + expected string } scenarios := []scenario{ { - testName: "Default case", - index: 5, - contextSize: 3, - expected: "git stash show -p --stat --color=always --unified=3 stash@{5}", + testName: "Default case", + index: 5, + contextSize: 3, + ignoreWhitespace: false, + expected: "git stash show -p --stat --color=always --unified=3 stash@{5}", }, { - testName: "Show diff with custom context size", - index: 5, - contextSize: 77, - expected: "git stash show -p --stat --color=always --unified=77 stash@{5}", + testName: "Show diff with custom context size", + index: 5, + contextSize: 77, + ignoreWhitespace: false, + expected: "git stash show -p --stat --color=always --unified=77 stash@{5}", + }, + { + testName: "Default case", + index: 5, + contextSize: 3, + ignoreWhitespace: true, + expected: "git stash show -p --stat --color=always --unified=3 --ignore-all-space stash@{5}", }, } @@ -127,7 +137,7 @@ func TestStashStashEntryCmdObj(t *testing.T) { userConfig.Git.DiffContextSize = s.contextSize instance := buildStashCommands(commonDeps{userConfig: userConfig}) - cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString() + cmdStr := instance.ShowStashEntryCmdObj(s.index, s.ignoreWhitespace).ToString() assert.Equal(t, s.expected, cmdStr) }) } diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index b7f53ec69..e4cf18ffc 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -126,8 +126,9 @@ func (self *CommitFilesController) GetOnRenderToMain() func() error { return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: pair, Main: &types.ViewUpdateOpts{ - Title: self.c.Tr.Patch, - Task: task, + Title: self.c.Tr.Patch, + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: task, }, Secondary: secondaryPatchPanelUpdateOpts(self.c), }) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 65fd16891..2876f97fb 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -174,8 +174,9 @@ func (self *FilesController) GetOnRenderToMain() func() error { return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: self.c.Tr.DiffTitle, - Task: types.NewRenderStringTask(self.c.Tr.NoChangedFiles), + Title: self.c.Tr.DiffTitle, + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: types.NewRenderStringTask(self.c.Tr.NoChangedFiles), }, }) } @@ -209,8 +210,9 @@ func (self *FilesController) GetOnRenderToMain() func() error { refreshOpts := types.RefreshMainOpts{ Pair: pair, Main: &types.ViewUpdateOpts{ - Task: types.NewRunPtyTask(cmdObj.GetCmd()), - Title: title, + Task: types.NewRunPtyTask(cmdObj.GetCmd()), + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Title: title, }, } @@ -223,8 +225,9 @@ func (self *FilesController) GetOnRenderToMain() func() error { } refreshOpts.Secondary = &types.ViewUpdateOpts{ - Title: title, - Task: types.NewRunPtyTask(cmdObj.GetCmd()), + Title: title, + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: types.NewRunPtyTask(cmdObj.GetCmd()), } } diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 701df93cd..8d18be2bf 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -59,8 +59,9 @@ func (self *DiffHelper) RenderDiff() error { return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: "Diff", - Task: task, + Title: "Diff", + SubTitle: self.IgnoringWhitespaceSubTitle(), + Task: task, }, }) } @@ -112,3 +113,11 @@ func (self *DiffHelper) WithDiffModeCheck(f func() error) error { return f() } + +func (self *DiffHelper) IgnoringWhitespaceSubTitle() string { + if self.c.State().GetIgnoreWhitespaceInDiffView() { + return self.c.Tr.IgnoreWhitespaceDiffViewSubTitle + } + + return "" +} diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index 38f850886..7dd93e6a6 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -73,7 +73,9 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt ref := self.c.Contexts().CommitFiles.CommitFileTreeViewModel.GetRef() to := ref.RefName() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) - diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView()) + // Passing false for ignoreWhitespace because the patch building panel + // doesn't work when whitespace is ignored + diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true, false) if err != nil { return err } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index d3dbff9d4..76d9afc20 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -176,8 +176,9 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error { return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: "Patch", - Task: task, + Title: "Patch", + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: task, }, Secondary: secondaryPatchPanelUpdateOpts(self.c), }) diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 4b5135884..0dac18f15 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -63,14 +63,20 @@ func (self *StashController) GetOnRenderToMain() func() error { if stashEntry == nil { task = types.NewRenderStringTask(self.c.Tr.NoStashEntries) } else { - task = types.NewRunPtyTask(self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index).GetCmd()) + task = types.NewRunPtyTask( + self.c.Git().Stash.ShowStashEntryCmdObj( + stashEntry.Index, + self.c.State().GetIgnoreWhitespaceInDiffView(), + ).GetCmd(), + ) } return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: "Stash", - Task: task, + Title: "Stash", + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: task, }, }) }) diff --git a/pkg/gui/controllers/sub_commits_controller.go b/pkg/gui/controllers/sub_commits_controller.go index e887b29d6..485d49820 100644 --- a/pkg/gui/controllers/sub_commits_controller.go +++ b/pkg/gui/controllers/sub_commits_controller.go @@ -46,8 +46,9 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error { return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: "Commit", - Task: task, + Title: "Commit", + SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), + Task: task, }, }) }) diff --git a/pkg/gui/controllers/toggle_whitespace_action.go b/pkg/gui/controllers/toggle_whitespace_action.go index 56eb023f3..f501338f4 100644 --- a/pkg/gui/controllers/toggle_whitespace_action.go +++ b/pkg/gui/controllers/toggle_whitespace_action.go @@ -1,7 +1,9 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" ) type ToggleWhitespaceAction struct { @@ -9,13 +11,19 @@ type ToggleWhitespaceAction struct { } func (self *ToggleWhitespaceAction) Call() error { - self.c.State().SetIgnoreWhitespaceInDiffView(!self.c.State().GetIgnoreWhitespaceInDiffView()) - - toastMessage := self.c.Tr.ShowingWhitespaceInDiffView - if self.c.State().GetIgnoreWhitespaceInDiffView() { - toastMessage = self.c.Tr.IgnoringWhitespaceInDiffView + contextsThatDontSupportIgnoringWhitespace := []types.ContextKey{ + context.STAGING_MAIN_CONTEXT_KEY, + context.STAGING_SECONDARY_CONTEXT_KEY, + context.PATCH_BUILDING_MAIN_CONTEXT_KEY, } - self.c.Toast(toastMessage) + + if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.CurrentContext().GetKey()) { + // Ignoring whitespace is not supported in these views. Let the user + // know that it's not going to work in case they try to turn it on. + return self.c.ErrorMsg(self.c.Tr.IgnoreWhitespaceNotSupportedHere) + } + + self.c.State().SetIgnoreWhitespaceInDiffView(!self.c.State().GetIgnoreWhitespaceInDiffView()) return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{}) } diff --git a/pkg/gui/main_panels.go b/pkg/gui/main_panels.go index e7c87c5e5..d3418b628 100644 --- a/pkg/gui/main_panels.go +++ b/pkg/gui/main_panels.go @@ -66,6 +66,8 @@ func (gui *Gui) RefreshMainView(opts *types.ViewUpdateOpts, context types.Contex view.Title = opts.Title } + view.Subtitle = opts.SubTitle + if err := gui.runTaskForView(view, opts.Task); err != nil { gui.c.Log.Error(err) return nil diff --git a/pkg/gui/types/rendering.go b/pkg/gui/types/rendering.go index b4e7bedcb..7a2f698ad 100644 --- a/pkg/gui/types/rendering.go +++ b/pkg/gui/types/rendering.go @@ -21,7 +21,8 @@ type MainViewPairs struct { } type ViewUpdateOpts struct { - Title string + Title string + SubTitle string Task UpdateTask } diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index decbb4ea8..9c19bd410 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -437,8 +437,6 @@ func chineseTranslationSet() TranslationSet { RandomTip: "随机小提示", SelectParentCommitForMerge: "选择父提交进行合并", ToggleWhitespaceInDiffView: "切换是否在差异视图中显示空白字符差异", - IgnoringWhitespaceInDiffView: "将会在差异视图中忽略空格字符差异", - ShowingWhitespaceInDiffView: "将会在差异视图中显示空白字符差异", IncreaseContextInDiffView: "扩大差异视图中显示的上下文范围", DecreaseContextInDiffView: "缩小差异视图中显示的上下文范围", CreatePullRequest: "创建抓取请求", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 5e34022d3..ea34ae022 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -481,8 +481,8 @@ type TranslationSet struct { RandomTip string SelectParentCommitForMerge string ToggleWhitespaceInDiffView string - IgnoringWhitespaceInDiffView string - ShowingWhitespaceInDiffView string + IgnoreWhitespaceDiffViewSubTitle string + IgnoreWhitespaceNotSupportedHere string IncreaseContextInDiffView string DecreaseContextInDiffView string CreatePullRequestOptions string @@ -1152,8 +1152,8 @@ func EnglishTranslationSet() TranslationSet { RandomTip: "Random Tip", SelectParentCommitForMerge: "Select parent commit for merge", ToggleWhitespaceInDiffView: "Toggle whether or not whitespace changes are shown in the diff view", - IgnoringWhitespaceInDiffView: "Whitespace will be ignored in the diff view", - ShowingWhitespaceInDiffView: "Whitespace will be shown in the diff view", + IgnoreWhitespaceDiffViewSubTitle: "(ignoring whitespace)", + IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view", IncreaseContextInDiffView: "Increase the size of the context shown around changes in the diff view", DecreaseContextInDiffView: "Decrease the size of the context shown around changes in the diff view", CreatePullRequest: "Create pull request", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index 1defdf1c9..d4efc55f0 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -452,9 +452,7 @@ func japaneseTranslationSet() TranslationSet { CommandLogHeader: "コマンドログの表示/非表示は '%s' で切り替えられます。\n", RandomTip: "ランダムTips", // SelectParentCommitForMerge: "Select parent commit for merge", - ToggleWhitespaceInDiffView: "空白文字の差分の表示有無を切り替え", - IgnoringWhitespaceInDiffView: "空白文字の変更は差分画面に表示されません", - ShowingWhitespaceInDiffView: "空白文字の変更は差分画面に表示されます", + ToggleWhitespaceInDiffView: "空白文字の差分の表示有無を切り替え", // IncreaseContextInDiffView: "Increase the size of the context shown around changes in the diff view", // DecreaseContextInDiffView: "Decrease the size of the context shown around changes in the diff view", CreatePullRequest: "pull requestを作成", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index ebdcb2ea5..ffb5b5da4 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -452,8 +452,6 @@ func koreanTranslationSet() TranslationSet { RandomTip: "랜덤 Tip", SelectParentCommitForMerge: "병합을 위한 상위 커밋 선택", ToggleWhitespaceInDiffView: "공백문자를 Diff 뷰에서 표시 여부 전환", - IgnoringWhitespaceInDiffView: "공백문자를 Diff 뷰에서 무시", - ShowingWhitespaceInDiffView: "공백문자를 Diff 뷰에서 표시", IncreaseContextInDiffView: "diff 보기의 변경 사항 주위에 표시되는 컨텍스트의 크기를 늘리기", DecreaseContextInDiffView: "diff 보기의 변경 사항 주위에 표시되는 컨텍스트 크기 줄이기", CreatePullRequest: "풀 리퀘스트 생성", diff --git a/pkg/integration/tests/diff/ignore_whitespace.go b/pkg/integration/tests/diff/ignore_whitespace.go index 157d3e7ff..157a66da9 100644 --- a/pkg/integration/tests/diff/ignore_whitespace.go +++ b/pkg/integration/tests/diff/ignore_whitespace.go @@ -35,8 +35,6 @@ var IgnoreWhitespace = NewIntegrationTest(NewIntegrationTestArgs{ IsFocused(). Press(keys.Universal.ToggleWhitespaceInDiffView) - t.ExpectToast(Equals("Whitespace will be ignored in the diff view")) - // lines with only whitespace changes are ignored (first and third lines) t.Views().Main().ContainsLines( Contains(` first-line`), @@ -50,8 +48,6 @@ var IgnoreWhitespace = NewIntegrationTest(NewIntegrationTestArgs{ IsFocused(). Press(keys.Universal.ToggleWhitespaceInDiffView) - t.ExpectToast(Equals("Whitespace will be shown in the diff view")) - t.Views().Main().ContainsLines( Contains(`-first-line`), Contains(`-old-second-line`),