diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 3e2c9e664..a522c81d0 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -230,7 +230,7 @@ func TestCommitShowCmdObj(t *testing.T) { type scenario struct { testName string filterPath string - contextSize int + contextSize uint64 similarityThreshold int ignoreWhitespace bool extDiffCmd string diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 207ddb126..874b47a9d 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -100,7 +100,7 @@ func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { testName string index int - contextSize int + contextSize uint64 similarityThreshold int ignoreWhitespace bool expected []string diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index a4270e732..18549fb9a 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -210,7 +210,7 @@ func TestWorkingTreeDiff(t *testing.T) { plain bool cached bool ignoreWhitespace bool - contextSize int + contextSize uint64 similarityThreshold int runner *oscommands.FakeCmdObjRunner } @@ -352,7 +352,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { reverse bool plain bool ignoreWhitespace bool - contextSize int + contextSize uint64 runner *oscommands.FakeCmdObjRunner } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index d68620867..884d4a0a0 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -457,7 +457,7 @@ type AppState struct { HideCommandLog bool IgnoreWhitespaceInDiffView bool - DiffContextSize int + DiffContextSize uint64 RenameSimilarityThreshold int LocalBranchSortOrder string RemoteBranchSortOrder string diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index cd9cf7481..432da5bc0 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -3,6 +3,7 @@ package controllers import ( "errors" "fmt" + "math" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -68,7 +69,9 @@ func (self *ContextLinesController) Increase() error { return err } - self.c.AppState.DiffContextSize++ + if self.c.AppState.DiffContextSize < math.MaxUint64 { + self.c.AppState.DiffContextSize++ + } return self.applyChange() } @@ -76,14 +79,14 @@ func (self *ContextLinesController) Increase() error { } func (self *ContextLinesController) Decrease() error { - old_size := self.c.AppState.DiffContextSize - - if self.isShowingDiff() && old_size > 1 { + if self.isShowingDiff() { if err := self.checkCanChangeContext(); err != nil { return err } - self.c.AppState.DiffContextSize = old_size - 1 + if self.c.AppState.DiffContextSize > 0 { + self.c.AppState.DiffContextSize-- + } return self.applyChange() } diff --git a/pkg/integration/tests/staging/diff_context_change.go b/pkg/integration/tests/staging/diff_context_change.go index 141f8bcec..a3f7b481f 100644 --- a/pkg/integration/tests/staging/diff_context_change.go +++ b/pkg/integration/tests/staging/diff_context_change.go @@ -127,6 +127,26 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{ Contains(`+3b`), Contains(` 4a`), ). + Press(keys.Universal.DecreaseContextInDiffView). + Tap(func() { + t.ExpectToast(Equals("Changed diff context size to 0")) + }). + SelectedLines( + Contains(`@@ -3,1 +3 @@`), + Contains(`-3a`), + Contains(`+3b`), + ). + Press(keys.Universal.IncreaseContextInDiffView). + Tap(func() { + t.ExpectToast(Equals("Changed diff context size to 1")) + }). + SelectedLines( + Contains(`@@ -2,3 +2,3 @@`), + Contains(` 2a`), + Contains(`-3a`), + Contains(`+3b`), + Contains(` 4a`), + ). Press(keys.Universal.IncreaseContextInDiffView). Tap(func() { t.ExpectToast(Equals("Changed diff context size to 2"))