1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-21 17:57:00 +02:00

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
-->
This commit is contained in:
Jesse Duffield 2024-11-19 08:27:38 +11:00 committed by GitHub
commit b62546c391
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -457,7 +457,7 @@ type AppState struct {
HideCommandLog bool
IgnoreWhitespaceInDiffView bool
DiffContextSize int
DiffContextSize uint64
RenameSimilarityThreshold int
LocalBranchSortOrder string
RemoteBranchSortOrder string

View File

@ -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()
}

View File

@ -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"))