From 111407d9a6742d329fb990cc3a9765bbd0c702a3 Mon Sep 17 00:00:00 2001 From: LU Jialin Date: Thu, 7 Nov 2024 23:09:32 -0800 Subject: [PATCH] use an unsigned_64 for DiffContextSize and add saturated add/subtract --- pkg/config/app_config.go | 2 +- pkg/gui/controllers/context_lines_controller.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index d68620867..884d4a0a0 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -457,7 +457,7 @@ type AppState struct { HideCommandLog bool IgnoreWhitespaceInDiffView bool - DiffContextSize int + DiffContextSize uint64 RenameSimilarityThreshold int LocalBranchSortOrder string RemoteBranchSortOrder string diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index cd9cf7481..432da5bc0 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -3,6 +3,7 @@ package controllers import ( "errors" "fmt" + "math" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -68,7 +69,9 @@ func (self *ContextLinesController) Increase() error { return err } - self.c.AppState.DiffContextSize++ + if self.c.AppState.DiffContextSize < math.MaxUint64 { + self.c.AppState.DiffContextSize++ + } return self.applyChange() } @@ -76,14 +79,14 @@ func (self *ContextLinesController) Increase() error { } func (self *ContextLinesController) Decrease() error { - old_size := self.c.AppState.DiffContextSize - - if self.isShowingDiff() && old_size > 1 { + if self.isShowingDiff() { if err := self.checkCanChangeContext(); err != nil { return err } - self.c.AppState.DiffContextSize = old_size - 1 + if self.c.AppState.DiffContextSize > 0 { + self.c.AppState.DiffContextSize-- + } return self.applyChange() }