1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-31 22:22:14 +02:00

Move IgnoreWhitespaceInDiffView to AppState, and persist it when it changes

This commit is contained in:
Stefan Haller 2023-07-26 11:29:43 +02:00
parent 045bce5dfc
commit be667682f0
12 changed files with 17 additions and 26 deletions

View File

@ -318,8 +318,9 @@ type AppState struct {
StartupPopupVersion int StartupPopupVersion int
// these are for custom commands typed in directly, not for custom commands in the lazygit config // these are for custom commands typed in directly, not for custom commands in the lazygit config
CustomCommandsHistory []string CustomCommandsHistory []string
HideCommandLog bool HideCommandLog bool
IgnoreWhitespaceInDiffView bool
} }
func getDefaultAppState() *AppState { func getDefaultAppState() *AppState {

View File

@ -114,7 +114,7 @@ func (self *CommitFilesController) GetOnRenderToMain() func() error {
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj( cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(
from, to, reverse, node.GetPath(), false, self.c.State().GetIgnoreWhitespaceInDiffView(), from, to, reverse, node.GetPath(), false, self.c.GetAppState().IgnoreWhitespaceInDiffView,
) )
task := types.NewRunPtyTask(cmdObj.GetCmd()) task := types.NewRunPtyTask(cmdObj.GetCmd())

View File

@ -201,7 +201,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
split := self.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) split := self.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges())
mainShowsStaged := !split && node.GetHasStagedChanges() mainShowsStaged := !split && node.GetHasStagedChanges()
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged, self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged, self.c.GetAppState().IgnoreWhitespaceInDiffView)
title := self.c.Tr.UnstagedChanges title := self.c.Tr.UnstagedChanges
if mainShowsStaged { if mainShowsStaged {
title = self.c.Tr.StagedChanges title = self.c.Tr.StagedChanges
@ -216,7 +216,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
} }
if split { if split {
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, true, self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, true, self.c.GetAppState().IgnoreWhitespaceInDiffView)
title := self.c.Tr.StagedChanges title := self.c.Tr.StagedChanges
if mainShowsStaged { if mainShowsStaged {

View File

@ -29,7 +29,7 @@ func (self *DiffHelper) DiffArgs() []string {
output = append(output, "-R") output = append(output, "-R")
} }
if self.c.State().GetIgnoreWhitespaceInDiffView() { if self.c.GetAppState().IgnoreWhitespaceInDiffView {
output = append(output, "--ignore-all-space") output = append(output, "--ignore-all-space")
} }
@ -113,7 +113,7 @@ func (self *DiffHelper) WithDiffModeCheck(f func() error) error {
} }
func (self *DiffHelper) IgnoringWhitespaceSubTitle() string { func (self *DiffHelper) IgnoringWhitespaceSubTitle() string {
if self.c.State().GetIgnoreWhitespaceInDiffView() { if self.c.GetAppState().IgnoreWhitespaceInDiffView {
return self.c.Tr.IgnoreWhitespaceDiffViewSubTitle return self.c.Tr.IgnoreWhitespaceDiffViewSubTitle
} }

View File

@ -177,7 +177,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error {
"ref": commit.Name, "ref": commit.Name,
})) }))
} else { } else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
task = types.NewRunPtyTask(cmdObj.GetCmd()) task = types.NewRunPtyTask(cmdObj.GetCmd())
} }

View File

@ -37,7 +37,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() error {
if commit == nil { if commit == nil {
task = types.NewRenderStringTask("No reflog history") task = types.NewRenderStringTask("No reflog history")
} else { } else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
task = types.NewRunPtyTask(cmdObj.GetCmd()) task = types.NewRunPtyTask(cmdObj.GetCmd())
} }

View File

@ -66,7 +66,7 @@ func (self *StashController) GetOnRenderToMain() func() error {
task = types.NewRunPtyTask( task = types.NewRunPtyTask(
self.c.Git().Stash.ShowStashEntryCmdObj( self.c.Git().Stash.ShowStashEntryCmdObj(
stashEntry.Index, stashEntry.Index,
self.c.State().GetIgnoreWhitespaceInDiffView(), self.c.GetAppState().IgnoreWhitespaceInDiffView,
).GetCmd(), ).GetCmd(),
) )
} }

View File

@ -38,7 +38,7 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error {
if commit == nil { if commit == nil {
task = types.NewRenderStringTask("No commits") task = types.NewRenderStringTask("No commits")
} else { } else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
task = types.NewRunPtyTask(cmdObj.GetCmd()) task = types.NewRunPtyTask(cmdObj.GetCmd())
} }

View File

@ -102,7 +102,7 @@ func (self *SubmodulesController) GetOnRenderToMain() func() error {
if file == nil { if file == nil {
task = types.NewRenderStringTask(prefix) task = types.NewRenderStringTask(prefix)
} else { } else {
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, self.c.State().GetIgnoreWhitespaceInDiffView()) cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, self.c.GetAppState().IgnoreWhitespaceInDiffView)
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix) task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
} }
} }

View File

@ -23,7 +23,10 @@ func (self *ToggleWhitespaceAction) Call() error {
return self.c.ErrorMsg(self.c.Tr.IgnoreWhitespaceNotSupportedHere) return self.c.ErrorMsg(self.c.Tr.IgnoreWhitespaceNotSupportedHere)
} }
self.c.State().SetIgnoreWhitespaceInDiffView(!self.c.State().GetIgnoreWhitespaceInDiffView()) self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
if err := self.c.SaveAppState(); err != nil {
self.c.Log.Errorf("error when saving app state: %v", err)
}
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{}) return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
} }

View File

@ -105,9 +105,6 @@ type Gui struct {
IsNewRepo bool IsNewRepo bool
// flag as to whether or not the diff view should ignore whitespace
IgnoreWhitespaceInDiffView bool
IsRefreshingFiles bool IsRefreshingFiles bool
// we use this to decide whether we'll return to the original directory that // we use this to decide whether we'll return to the original directory that
@ -144,14 +141,6 @@ type StateAccessor struct {
var _ types.IStateAccessor = new(StateAccessor) var _ types.IStateAccessor = new(StateAccessor)
func (self *StateAccessor) GetIgnoreWhitespaceInDiffView() bool {
return self.gui.IgnoreWhitespaceInDiffView
}
func (self *StateAccessor) SetIgnoreWhitespaceInDiffView(value bool) {
self.gui.IgnoreWhitespaceInDiffView = value
}
func (self *StateAccessor) GetRepoPathStack() *utils.StringStack { func (self *StateAccessor) GetRepoPathStack() *utils.StringStack {
return self.gui.RepoPathStack return self.gui.RepoPathStack
} }

View File

@ -243,8 +243,6 @@ type Mutexes struct {
} }
type IStateAccessor interface { type IStateAccessor interface {
GetIgnoreWhitespaceInDiffView() bool
SetIgnoreWhitespaceInDiffView(value bool)
GetRepoPathStack() *utils.StringStack GetRepoPathStack() *utils.StringStack
GetRepoState() IRepoStateAccessor GetRepoState() IRepoStateAccessor
// tells us whether we're currently updating lazygit // tells us whether we're currently updating lazygit