mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-06 03:53:59 +02:00
Merge pull request #2641 from stefanhaller/visualize-ignore-whitespace-config
This commit is contained in:
commit
2304ffc804
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -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),
|
||||
})
|
||||
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 ""
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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),
|
||||
})
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
@ -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{})
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -21,7 +21,8 @@ type MainViewPairs struct {
|
||||
}
|
||||
|
||||
type ViewUpdateOpts struct {
|
||||
Title string
|
||||
Title string
|
||||
SubTitle string
|
||||
|
||||
Task UpdateTask
|
||||
}
|
||||
|
@ -437,8 +437,6 @@ func chineseTranslationSet() TranslationSet {
|
||||
RandomTip: "随机小提示",
|
||||
SelectParentCommitForMerge: "选择父提交进行合并",
|
||||
ToggleWhitespaceInDiffView: "切换是否在差异视图中显示空白字符差异",
|
||||
IgnoringWhitespaceInDiffView: "将会在差异视图中忽略空格字符差异",
|
||||
ShowingWhitespaceInDiffView: "将会在差异视图中显示空白字符差异",
|
||||
IncreaseContextInDiffView: "扩大差异视图中显示的上下文范围",
|
||||
DecreaseContextInDiffView: "缩小差异视图中显示的上下文范围",
|
||||
CreatePullRequest: "创建抓取请求",
|
||||
|
@ -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",
|
||||
|
@ -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を作成",
|
||||
|
@ -452,8 +452,6 @@ func koreanTranslationSet() TranslationSet {
|
||||
RandomTip: "랜덤 Tip",
|
||||
SelectParentCommitForMerge: "병합을 위한 상위 커밋 선택",
|
||||
ToggleWhitespaceInDiffView: "공백문자를 Diff 뷰에서 표시 여부 전환",
|
||||
IgnoringWhitespaceInDiffView: "공백문자를 Diff 뷰에서 무시",
|
||||
ShowingWhitespaceInDiffView: "공백문자를 Diff 뷰에서 표시",
|
||||
IncreaseContextInDiffView: "diff 보기의 변경 사항 주위에 표시되는 컨텍스트의 크기를 늘리기",
|
||||
DecreaseContextInDiffView: "diff 보기의 변경 사항 주위에 표시되는 컨텍스트 크기 줄이기",
|
||||
CreatePullRequest: "풀 리퀘스트 생성",
|
||||
|
@ -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`),
|
||||
|
Loading…
Reference in New Issue
Block a user