1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/diff_context_size.go
Jesse Duffield 364c5db19c shorten name
2022-01-09 14:09:53 +11:00

48 lines
1.2 KiB
Go

package gui
import (
"errors"
)
func isShowingDiff(gui *Gui) bool {
key := gui.currentStaticContext().GetKey()
return key == FILES_CONTEXT_KEY || key == COMMIT_FILES_CONTEXT_KEY || key == STASH_CONTEXT_KEY || key == BRANCH_COMMITS_CONTEXT_KEY || key == SUB_COMMITS_CONTEXT_KEY || key == MAIN_STAGING_CONTEXT_KEY || key == MAIN_PATCH_BUILDING_CONTEXT_KEY
}
func (gui *Gui) IncreaseContextInDiffView() error {
if isShowingDiff(gui) {
if err := gui.CheckCanChangeContext(); err != nil {
return gui.surfaceError(err)
}
gui.UserConfig.Git.DiffContextSize = gui.UserConfig.Git.DiffContextSize + 1
return gui.currentStaticContext().HandleRenderToMain()
}
return nil
}
func (gui *Gui) DecreaseContextInDiffView() error {
old_size := gui.UserConfig.Git.DiffContextSize
if isShowingDiff(gui) && old_size > 1 {
if err := gui.CheckCanChangeContext(); err != nil {
return gui.surfaceError(err)
}
gui.UserConfig.Git.DiffContextSize = old_size - 1
return gui.currentStaticContext().HandleRenderToMain()
}
return nil
}
func (gui *Gui) CheckCanChangeContext() error {
if gui.Git.Patch.PatchManager.Active() {
return errors.New(gui.Tr.CantChangeContextSizeError)
}
return nil
}