1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

Add the DecreaseContextInDiffView function

This commit is contained in:
DerTeta 2021-09-11 19:29:33 +02:00 committed by Jesse Duffield
parent e1cf6912db
commit ba844c18a5
2 changed files with 71 additions and 0 deletions

View File

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

View File

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