mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +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:
commit
b62546c391
6 changed files with 33 additions and 10 deletions
|
@ -230,7 +230,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
filterPath string
|
filterPath string
|
||||||
contextSize int
|
contextSize uint64
|
||||||
similarityThreshold int
|
similarityThreshold int
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
extDiffCmd string
|
extDiffCmd string
|
||||||
|
|
|
@ -100,7 +100,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
index int
|
index int
|
||||||
contextSize int
|
contextSize uint64
|
||||||
similarityThreshold int
|
similarityThreshold int
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
expected []string
|
expected []string
|
||||||
|
|
|
@ -210,7 +210,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
||||||
plain bool
|
plain bool
|
||||||
cached bool
|
cached bool
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
contextSize int
|
contextSize uint64
|
||||||
similarityThreshold int
|
similarityThreshold int
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
|
||||||
reverse bool
|
reverse bool
|
||||||
plain bool
|
plain bool
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
contextSize int
|
contextSize uint64
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -457,7 +457,7 @@ type AppState struct {
|
||||||
|
|
||||||
HideCommandLog bool
|
HideCommandLog bool
|
||||||
IgnoreWhitespaceInDiffView bool
|
IgnoreWhitespaceInDiffView bool
|
||||||
DiffContextSize int
|
DiffContextSize uint64
|
||||||
RenameSimilarityThreshold int
|
RenameSimilarityThreshold int
|
||||||
LocalBranchSortOrder string
|
LocalBranchSortOrder string
|
||||||
RemoteBranchSortOrder string
|
RemoteBranchSortOrder string
|
||||||
|
|
|
@ -3,6 +3,7 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
"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"
|
||||||
|
@ -68,7 +69,9 @@ func (self *ContextLinesController) Increase() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.c.AppState.DiffContextSize < math.MaxUint64 {
|
||||||
self.c.AppState.DiffContextSize++
|
self.c.AppState.DiffContextSize++
|
||||||
|
}
|
||||||
return self.applyChange()
|
return self.applyChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,14 +79,14 @@ func (self *ContextLinesController) Increase() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ContextLinesController) Decrease() error {
|
func (self *ContextLinesController) Decrease() error {
|
||||||
old_size := self.c.AppState.DiffContextSize
|
if self.isShowingDiff() {
|
||||||
|
|
||||||
if self.isShowingDiff() && old_size > 1 {
|
|
||||||
if err := self.checkCanChangeContext(); err != nil {
|
if err := self.checkCanChangeContext(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
self.c.AppState.DiffContextSize = old_size - 1
|
if self.c.AppState.DiffContextSize > 0 {
|
||||||
|
self.c.AppState.DiffContextSize--
|
||||||
|
}
|
||||||
return self.applyChange()
|
return self.applyChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,26 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
Contains(`+3b`),
|
Contains(`+3b`),
|
||||||
Contains(` 4a`),
|
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).
|
Press(keys.Universal.IncreaseContextInDiffView).
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectToast(Equals("Changed diff context size to 2"))
|
t.ExpectToast(Equals("Changed diff context size to 2"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue