mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Enable { and } to change diff context size in branches and tags panels in diffing mode
Actually, we simply enable them in any panel, even those that can never show a diff. Since the commands show a toast, that's enough feedback to understand what happened; the change will take effect the next time you switch to a panel that does show diffs. Same for ( and ) to change the rename threshold.
This commit is contained in:
parent
17e7044d7c
commit
9dd121dfa3
|
|
@ -7,25 +7,10 @@ import (
|
|||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// This controller lets you change the context size for diffs. The 'context' in 'context size' refers to the conventional meaning of the word 'context' in a diff, as opposed to lazygit's own idea of a 'context'.
|
||||
|
||||
var CONTEXT_KEYS_SHOWING_DIFFS = []types.ContextKey{
|
||||
context.FILES_CONTEXT_KEY,
|
||||
context.COMMIT_FILES_CONTEXT_KEY,
|
||||
context.STASH_CONTEXT_KEY,
|
||||
context.LOCAL_COMMITS_CONTEXT_KEY,
|
||||
context.SUB_COMMITS_CONTEXT_KEY,
|
||||
context.STAGING_MAIN_CONTEXT_KEY,
|
||||
context.STAGING_SECONDARY_CONTEXT_KEY,
|
||||
context.PATCH_BUILDING_MAIN_CONTEXT_KEY,
|
||||
context.PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
|
||||
context.NORMAL_MAIN_CONTEXT_KEY,
|
||||
context.NORMAL_SECONDARY_CONTEXT_KEY,
|
||||
}
|
||||
|
||||
type ContextLinesController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
|
|
@ -66,33 +51,25 @@ func (self *ContextLinesController) Context() types.Context {
|
|||
}
|
||||
|
||||
func (self *ContextLinesController) Increase() error {
|
||||
if self.isShowingDiff() {
|
||||
if err := self.checkCanChangeContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if self.c.UserConfig().Git.DiffContextSize < math.MaxUint64 {
|
||||
self.c.UserConfig().Git.DiffContextSize++
|
||||
}
|
||||
return self.applyChange()
|
||||
if err := self.checkCanChangeContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
if self.c.UserConfig().Git.DiffContextSize < math.MaxUint64 {
|
||||
self.c.UserConfig().Git.DiffContextSize++
|
||||
}
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
func (self *ContextLinesController) Decrease() error {
|
||||
if self.isShowingDiff() {
|
||||
if err := self.checkCanChangeContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if self.c.UserConfig().Git.DiffContextSize > 0 {
|
||||
self.c.UserConfig().Git.DiffContextSize--
|
||||
}
|
||||
return self.applyChange()
|
||||
if err := self.checkCanChangeContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
if self.c.UserConfig().Git.DiffContextSize > 0 {
|
||||
self.c.UserConfig().Git.DiffContextSize--
|
||||
}
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
func (self *ContextLinesController) applyChange() error {
|
||||
|
|
@ -119,13 +96,6 @@ func (self *ContextLinesController) checkCanChangeContext() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *ContextLinesController) isShowingDiff() bool {
|
||||
return lo.Contains(
|
||||
CONTEXT_KEYS_SHOWING_DIFFS,
|
||||
self.currentSidePanel().GetKey(),
|
||||
)
|
||||
}
|
||||
|
||||
func (self *ContextLinesController) currentSidePanel() types.Context {
|
||||
currentContext := self.c.Context().CurrentStatic()
|
||||
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
||||
|
|
|
|||
|
|
@ -5,20 +5,10 @@ import (
|
|||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// This controller lets you change the similarity threshold for detecting renames.
|
||||
|
||||
var CONTEXT_KEYS_SHOWING_RENAMES = []types.ContextKey{
|
||||
context.FILES_CONTEXT_KEY,
|
||||
context.SUB_COMMITS_CONTEXT_KEY,
|
||||
context.LOCAL_COMMITS_CONTEXT_KEY,
|
||||
context.STASH_CONTEXT_KEY,
|
||||
context.NORMAL_MAIN_CONTEXT_KEY,
|
||||
context.NORMAL_SECONDARY_CONTEXT_KEY,
|
||||
}
|
||||
|
||||
type RenameSimilarityThresholdController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
|
|
@ -61,23 +51,21 @@ func (self *RenameSimilarityThresholdController) Context() types.Context {
|
|||
func (self *RenameSimilarityThresholdController) Increase() error {
|
||||
old_size := self.c.UserConfig().Git.RenameSimilarityThreshold
|
||||
|
||||
if self.isShowingRenames() && old_size < 100 {
|
||||
if old_size < 100 {
|
||||
self.c.UserConfig().Git.RenameSimilarityThreshold = min(100, old_size+5)
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
return nil
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
func (self *RenameSimilarityThresholdController) Decrease() error {
|
||||
old_size := self.c.UserConfig().Git.RenameSimilarityThreshold
|
||||
|
||||
if self.isShowingRenames() && old_size > 5 {
|
||||
if old_size > 5 {
|
||||
self.c.UserConfig().Git.RenameSimilarityThreshold = max(5, old_size-5)
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
return nil
|
||||
return self.applyChange()
|
||||
}
|
||||
|
||||
func (self *RenameSimilarityThresholdController) applyChange() error {
|
||||
|
|
@ -94,13 +82,6 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *RenameSimilarityThresholdController) isShowingRenames() bool {
|
||||
return lo.Contains(
|
||||
CONTEXT_KEYS_SHOWING_RENAMES,
|
||||
self.currentSidePanel().GetKey(),
|
||||
)
|
||||
}
|
||||
|
||||
func (self *RenameSimilarityThresholdController) currentSidePanel() types.Context {
|
||||
currentContext := self.c.Context().CurrentStatic()
|
||||
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
||||
|
|
|
|||
Loading…
Reference in a new issue