mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Move diff context size from UserConfig to AppState
This commit is contained in:
parent
f7db17f7d0
commit
7774fe0ab3
11 changed files with 21 additions and 16 deletions
|
@ -117,7 +117,6 @@ git:
|
|||
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
|
||||
disableForcePushing: false
|
||||
parseEmoji: false
|
||||
diffContextSize: 3 # how many lines of context are shown around a change in diffs
|
||||
os:
|
||||
copyToClipboardCmd: '' # See 'Custom Command for Copying to Clipboard' section
|
||||
editPreset: '' # see 'Configuring File Editing' section
|
||||
|
|
|
@ -197,7 +197,7 @@ func (self *CommitCommands) AmendHeadCmdObj() oscommands.ICmdObj {
|
|||
}
|
||||
|
||||
func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj {
|
||||
contextSize := self.UserConfig.Git.DiffContextSize
|
||||
contextSize := self.AppState.DiffContextSize
|
||||
|
||||
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
||||
cmdArgs := NewGitCmd("show").
|
||||
|
|
|
@ -237,10 +237,10 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
userConfig := config.GetDefaultConfig()
|
||||
userConfig.Git.DiffContextSize = s.contextSize
|
||||
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
|
||||
appState := &config.AppState{}
|
||||
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||
appState.DiffContextSize = s.contextSize
|
||||
|
||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
|
||||
instance := buildCommitCommands(commonDeps{userConfig: userConfig, appState: appState, runner: runner})
|
||||
|
|
|
@ -85,7 +85,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
|
|||
Arg("-p").
|
||||
Arg("--stat").
|
||||
Arg(fmt.Sprintf("--color=%s", self.UserConfig.Git.Paging.ColorArg)).
|
||||
Arg(fmt.Sprintf("--unified=%d", self.UserConfig.Git.DiffContextSize)).
|
||||
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
|
||||
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||
Arg(fmt.Sprintf("stash@{%d}", index)).
|
||||
ToArgv()
|
||||
|
|
|
@ -134,9 +134,9 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
userConfig := config.GetDefaultConfig()
|
||||
userConfig.Git.DiffContextSize = s.contextSize
|
||||
appState := &config.AppState{}
|
||||
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||
appState.DiffContextSize = s.contextSize
|
||||
instance := buildStashCommands(commonDeps{userConfig: userConfig, appState: appState})
|
||||
|
||||
cmdStr := instance.ShowStashEntryCmdObj(s.index).Args()
|
||||
|
|
|
@ -240,7 +240,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
|
|||
colorArg = "never"
|
||||
}
|
||||
|
||||
contextSize := self.UserConfig.Git.DiffContextSize
|
||||
contextSize := self.AppState.DiffContextSize
|
||||
prevPath := node.GetPreviousPath()
|
||||
noIndex := !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile()
|
||||
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
||||
|
@ -271,7 +271,7 @@ func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bo
|
|||
}
|
||||
|
||||
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
||||
contextSize := self.UserConfig.Git.DiffContextSize
|
||||
contextSize := self.AppState.DiffContextSize
|
||||
|
||||
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||
if plain {
|
||||
|
|
|
@ -309,9 +309,9 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
userConfig := config.GetDefaultConfig()
|
||||
userConfig.Git.DiffContextSize = s.contextSize
|
||||
appState := &config.AppState{}
|
||||
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||
appState.DiffContextSize = s.contextSize
|
||||
|
||||
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: appState})
|
||||
result := instance.WorktreeFileDiff(s.file, s.plain, s.cached)
|
||||
|
@ -375,9 +375,9 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
|
|||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
userConfig := config.GetDefaultConfig()
|
||||
userConfig.Git.DiffContextSize = s.contextSize
|
||||
appState := &config.AppState{}
|
||||
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||
appState.DiffContextSize = s.contextSize
|
||||
|
||||
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: appState})
|
||||
|
||||
|
|
|
@ -322,6 +322,7 @@ type AppState struct {
|
|||
CustomCommandsHistory []string
|
||||
HideCommandLog bool
|
||||
IgnoreWhitespaceInDiffView bool
|
||||
DiffContextSize int
|
||||
}
|
||||
|
||||
func getDefaultAppState() *AppState {
|
||||
|
@ -329,6 +330,7 @@ func getDefaultAppState() *AppState {
|
|||
LastUpdateCheck: 0,
|
||||
RecentRepos: []string{},
|
||||
StartupPopupVersion: 0,
|
||||
DiffContextSize: 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,9 +95,8 @@ type GitConfig struct {
|
|||
DisableForcePushing bool `yaml:"disableForcePushing"`
|
||||
CommitPrefixes map[string]CommitPrefixConfig `yaml:"commitPrefixes"`
|
||||
// this should really be under 'gui', not 'git'
|
||||
ParseEmoji bool `yaml:"parseEmoji"`
|
||||
Log LogConfig `yaml:"log"`
|
||||
DiffContextSize int `yaml:"diffContextSize"`
|
||||
ParseEmoji bool `yaml:"parseEmoji"`
|
||||
Log LogConfig `yaml:"log"`
|
||||
}
|
||||
|
||||
type PagingConfig struct {
|
||||
|
@ -497,7 +496,6 @@ func GetDefaultConfig() *UserConfig {
|
|||
DisableForcePushing: false,
|
||||
CommitPrefixes: map[string]CommitPrefixConfig(nil),
|
||||
ParseEmoji: false,
|
||||
DiffContextSize: 3,
|
||||
},
|
||||
Refresher: RefresherConfig{
|
||||
RefreshInterval: 10,
|
||||
|
|
|
@ -2,6 +2,7 @@ package controllers
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
|
@ -65,7 +66,7 @@ func (self *ContextLinesController) Increase() error {
|
|||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
self.c.UserConfig.Git.DiffContextSize = self.c.UserConfig.Git.DiffContextSize + 1
|
||||
self.c.AppState.DiffContextSize++
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
|
@ -73,14 +74,14 @@ func (self *ContextLinesController) Increase() error {
|
|||
}
|
||||
|
||||
func (self *ContextLinesController) Decrease() error {
|
||||
old_size := self.c.UserConfig.Git.DiffContextSize
|
||||
old_size := self.c.AppState.DiffContextSize
|
||||
|
||||
if self.isShowingDiff() && old_size > 1 {
|
||||
if err := self.checkCanChangeContext(); err != nil {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
self.c.UserConfig.Git.DiffContextSize = old_size - 1
|
||||
self.c.AppState.DiffContextSize = old_size - 1
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
|
@ -88,6 +89,9 @@ func (self *ContextLinesController) Decrease() error {
|
|||
}
|
||||
|
||||
func (self *ContextLinesController) applyChange() error {
|
||||
self.c.Toast(fmt.Sprintf(self.c.Tr.DiffContextSizeChanged, self.c.AppState.DiffContextSize))
|
||||
self.c.SaveAppStateAndLogError()
|
||||
|
||||
currentContext := self.c.CurrentStaticContext()
|
||||
switch currentContext.GetKey() {
|
||||
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
|
||||
|
|
|
@ -512,6 +512,7 @@ type TranslationSet struct {
|
|||
IgnoreWhitespaceNotSupportedHere string
|
||||
IncreaseContextInDiffView string
|
||||
DecreaseContextInDiffView string
|
||||
DiffContextSizeChanged string
|
||||
CreatePullRequestOptions string
|
||||
DefaultBranch string
|
||||
SelectBranch string
|
||||
|
@ -1293,6 +1294,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||
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",
|
||||
DiffContextSizeChanged: "Changed diff context size to %d",
|
||||
CreatePullRequestOptions: "Create pull request options",
|
||||
DefaultBranch: "Default branch",
|
||||
SelectBranch: "Select branch",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue