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