1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Save IgnoreWhitespaceInDiffView in state.yml (#2830)

This commit is contained in:
Stefan Haller 2023-07-31 11:48:51 +02:00 committed by GitHub
commit 6de9e230a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 27 deletions

View File

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

View File

@ -114,7 +114,7 @@ func (self *CommitFilesController) GetOnRenderToMain() func() error {
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
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())

View File

@ -201,7 +201,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
split := self.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && 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
if mainShowsStaged {
title = self.c.Tr.StagedChanges
@ -216,7 +216,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
}
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
if mainShowsStaged {

View File

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

View File

@ -177,7 +177,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error {
"ref": commit.Name,
}))
} 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())
}

View File

@ -37,7 +37,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() error {
if commit == nil {
task = types.NewRenderStringTask("No reflog history")
} 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())
}

View File

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

View File

@ -38,7 +38,7 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error {
if commit == nil {
task = types.NewRenderStringTask("No commits")
} 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())
}

View File

@ -102,7 +102,7 @@ func (self *SubmodulesController) GetOnRenderToMain() func() error {
if file == nil {
task = types.NewRenderStringTask(prefix)
} 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)
}
}

View File

@ -23,7 +23,10 @@ func (self *ToggleWhitespaceAction) Call() error {
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{})
}

View File

@ -24,7 +24,9 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
show := !gui.c.State().GetShowExtrasWindow()
gui.c.State().SetShowExtrasWindow(show)
gui.c.GetAppState().HideCommandLog = !show
_ = gui.c.SaveAppState()
if err := gui.c.SaveAppState(); err != nil {
gui.c.Log.Errorf("error when saving app state: %v", err)
}
return nil
},
},

View File

@ -105,9 +105,6 @@ type Gui struct {
IsNewRepo bool
// flag as to whether or not the diff view should ignore whitespace
IgnoreWhitespaceInDiffView bool
IsRefreshingFiles bool
// 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)
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 {
return self.gui.RepoPathStack
}

View File

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