Skip to content

Commit b62546c

Browse files
Allow DiffContextSize to be decreased to zero (#4050)
- **PR Description** Per #4012, the diff context size should be able to be decreased to zero. I update the type def for DiffContextSize to be an unsigned integer and add saturated add and subtraction in `context_lines_controller.go` where the variable is updated (++ or --) - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [x] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
2 parents 9f03f9e + de8dc93 commit b62546c

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

pkg/commands/git_commands/commit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func TestCommitShowCmdObj(t *testing.T) {
230230
type scenario struct {
231231
testName string
232232
filterPath string
233-
contextSize int
233+
contextSize uint64
234234
similarityThreshold int
235235
ignoreWhitespace bool
236236
extDiffCmd string

pkg/commands/git_commands/stash_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
100100
type scenario struct {
101101
testName string
102102
index int
103-
contextSize int
103+
contextSize uint64
104104
similarityThreshold int
105105
ignoreWhitespace bool
106106
expected []string

pkg/commands/git_commands/working_tree_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func TestWorkingTreeDiff(t *testing.T) {
210210
plain bool
211211
cached bool
212212
ignoreWhitespace bool
213-
contextSize int
213+
contextSize uint64
214214
similarityThreshold int
215215
runner *oscommands.FakeCmdObjRunner
216216
}
@@ -352,7 +352,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
352352
reverse bool
353353
plain bool
354354
ignoreWhitespace bool
355-
contextSize int
355+
contextSize uint64
356356
runner *oscommands.FakeCmdObjRunner
357357
}
358358

pkg/config/app_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ type AppState struct {
457457

458458
HideCommandLog bool
459459
IgnoreWhitespaceInDiffView bool
460-
DiffContextSize int
460+
DiffContextSize uint64
461461
RenameSimilarityThreshold int
462462
LocalBranchSortOrder string
463463
RemoteBranchSortOrder string

pkg/gui/controllers/context_lines_controller.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controllers
33
import (
44
"errors"
55
"fmt"
6+
"math"
67

78
"github.com/jesseduffield/lazygit/pkg/gui/context"
89
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -68,22 +69,24 @@ func (self *ContextLinesController) Increase() error {
6869
return err
6970
}
7071

71-
self.c.AppState.DiffContextSize++
72+
if self.c.AppState.DiffContextSize < math.MaxUint64 {
73+
self.c.AppState.DiffContextSize++
74+
}
7275
return self.applyChange()
7376
}
7477

7578
return nil
7679
}
7780

7881
func (self *ContextLinesController) Decrease() error {
79-
old_size := self.c.AppState.DiffContextSize
80-
81-
if self.isShowingDiff() && old_size > 1 {
82+
if self.isShowingDiff() {
8283
if err := self.checkCanChangeContext(); err != nil {
8384
return err
8485
}
8586

86-
self.c.AppState.DiffContextSize = old_size - 1
87+
if self.c.AppState.DiffContextSize > 0 {
88+
self.c.AppState.DiffContextSize--
89+
}
8790
return self.applyChange()
8891
}
8992

pkg/integration/tests/staging/diff_context_change.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
127127
Contains(`+3b`),
128128
Contains(` 4a`),
129129
).
130+
Press(keys.Universal.DecreaseContextInDiffView).
131+
Tap(func() {
132+
t.ExpectToast(Equals("Changed diff context size to 0"))
133+
}).
134+
SelectedLines(
135+
Contains(`@@ -3,1 +3 @@`),
136+
Contains(`-3a`),
137+
Contains(`+3b`),
138+
).
139+
Press(keys.Universal.IncreaseContextInDiffView).
140+
Tap(func() {
141+
t.ExpectToast(Equals("Changed diff context size to 1"))
142+
}).
143+
SelectedLines(
144+
Contains(`@@ -2,3 +2,3 @@`),
145+
Contains(` 2a`),
146+
Contains(`-3a`),
147+
Contains(`+3b`),
148+
Contains(` 4a`),
149+
).
130150
Press(keys.Universal.IncreaseContextInDiffView).
131151
Tap(func() {
132152
t.ExpectToast(Equals("Changed diff context size to 2"))

0 commit comments

Comments
 (0)