diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/diff_context_size.go | 11 | ||||
-rw-r--r-- | pkg/gui/diff_context_size_test.go | 60 |
2 files changed, 71 insertions, 0 deletions
diff --git a/pkg/gui/diff_context_size.go b/pkg/gui/diff_context_size.go index 3e6e6b4a2..a54a9c418 100644 --- a/pkg/gui/diff_context_size.go +++ b/pkg/gui/diff_context_size.go @@ -14,3 +14,14 @@ func (gui *Gui) IncreaseContextInDiffView() error { return nil } + +func (gui *Gui) DecreaseContextInDiffView() error { + old_size := gui.Config.GetUserConfig().Git.DiffContextSize + + if isShowingDiff(gui) && old_size > 1 { + gui.Config.GetUserConfig().Git.DiffContextSize = old_size - 1 + return gui.postRefreshUpdate(gui.currentStaticContext()) + } + + return nil +} diff --git a/pkg/gui/diff_context_size_test.go b/pkg/gui/diff_context_size_test.go index 61d0bc728..3725a81a6 100644 --- a/pkg/gui/diff_context_size_test.go +++ b/pkg/gui/diff_context_size_test.go @@ -80,3 +80,63 @@ func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) { assert.Equal(t, 1, gui.Config.GetUserConfig().Git.DiffContextSize, string(context.GetKey())) } } + +func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) { + contexts := []func(gui *Gui) Context { + func(gui *Gui) Context { return gui.State.Contexts.Files }, + func(gui *Gui) Context { return gui.State.Contexts.BranchCommits }, + func(gui *Gui) Context { return gui.State.Contexts.CommitFiles }, + func(gui *Gui) Context { return gui.State.Contexts.Stash }, + func(gui *Gui) Context { return gui.State.Contexts.Staging }, + func(gui *Gui) Context { return gui.State.Contexts.PatchBuilding }, + func(gui *Gui) Context { return gui.State.Contexts.SubCommits }, + } + + for _, c := range contexts { + gui := NewDummyGui() + context := c(gui) + setupGuiForTest(gui) + gui.Config.GetUserConfig().Git.DiffContextSize = 2 + gui.pushContextDirect(context) + + gui.DecreaseContextInDiffView() + + assert.Equal(t, 1, gui.Config.GetUserConfig().Git.DiffContextSize, string(context.GetKey())) + } +} + +func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) { + contexts := []func(gui *Gui) Context { + func(gui *Gui) Context { return gui.State.Contexts.Status }, + func(gui *Gui) Context { return gui.State.Contexts.Submodules }, + func(gui *Gui) Context { return gui.State.Contexts.Remotes }, + func(gui *Gui) Context { return gui.State.Contexts.Normal }, + func(gui *Gui) Context { return gui.State.Contexts.ReflogCommits }, + func(gui *Gui) Context { return gui.State.Contexts.RemoteBranches }, + func(gui *Gui) Context { return gui.State.Contexts.Tags }, + func(gui *Gui) Context { return gui.State.Contexts.Merging }, + func(gui *Gui) Context { return gui.State.Contexts.CommandLog }, + } + + for _, c := range contexts { + gui := NewDummyGui() + context := c(gui) + setupGuiForTest(gui) + gui.Config.GetUserConfig().Git.DiffContextSize = 2 + gui.pushContextDirect(context) + + gui.DecreaseContextInDiffView() + + assert.Equal(t, 2, gui.Config.GetUserConfig().Git.DiffContextSize, string(context.GetKey())) + } +} + +func TestDecreasesContextInDiffViewNoFurtherThanOne(t *testing.T) { + gui := NewDummyGui() + setupGuiForTest(gui) + gui.Config.GetUserConfig().Git.DiffContextSize = 1 + + gui.DecreaseContextInDiffView() + + assert.Equal(t, 1, gui.Config.GetUserConfig().Git.DiffContextSize) +} |