Skip to content

Commit d4725f5

Browse files
committed
Remove utils.Clamp, use lo.Clamp instead
1 parent c4c2ff2 commit d4725f5

File tree

5 files changed

+9
-17
lines changed

5 files changed

+9
-17
lines changed

pkg/commands/patch/patch.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package patch
22

33
import (
4-
"github.com/jesseduffield/lazygit/pkg/utils"
54
"github.com/samber/lo"
65
)
76

@@ -54,7 +53,7 @@ func (self *Patch) Lines() []*PatchLine {
5453

5554
// Returns the patch line index of the first line in the given hunk
5655
func (self *Patch) HunkStartIdx(hunkIndex int) int {
57-
hunkIndex = utils.Clamp(hunkIndex, 0, len(self.hunks)-1)
56+
hunkIndex = lo.Clamp(hunkIndex, 0, len(self.hunks)-1)
5857

5958
result := len(self.header)
6059
for i := 0; i < hunkIndex; i++ {
@@ -65,7 +64,7 @@ func (self *Patch) HunkStartIdx(hunkIndex int) int {
6564

6665
// Returns the patch line index of the last line in the given hunk
6766
func (self *Patch) HunkEndIdx(hunkIndex int) int {
68-
hunkIndex = utils.Clamp(hunkIndex, 0, len(self.hunks)-1)
67+
hunkIndex = lo.Clamp(hunkIndex, 0, len(self.hunks)-1)
6968

7069
return self.HunkStartIdx(hunkIndex) + self.hunks[hunkIndex].lineCount() - 1
7170
}
@@ -118,7 +117,7 @@ func (self *Patch) HunkContainingLine(idx int) int {
118117

119118
// Returns the patch line index of the next change (i.e. addition or deletion).
120119
func (self *Patch) GetNextChangeIdx(idx int) int {
121-
idx = utils.Clamp(idx, 0, self.LineCount()-1)
120+
idx = lo.Clamp(idx, 0, self.LineCount()-1)
122121

123122
lines := self.Lines()
124123

pkg/gui/context/list_renderer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (self *ListRenderer) ModelIndexToViewIndex(modelIndex int) int {
5252
}
5353

5454
func (self *ListRenderer) ViewIndexToModelIndex(viewIndex int) int {
55-
viewIndex = utils.Clamp(viewIndex, 0, self.list.Len()+self.numNonModelItems)
55+
viewIndex = lo.Clamp(viewIndex, 0, self.list.Len()+self.numNonModelItems)
5656
if self.modelIndicesByViewIndex != nil {
5757
return self.modelIndicesByViewIndex[viewIndex]
5858
}

pkg/gui/context/traits/list_cursor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package traits
33
import (
44
"github.com/jesseduffield/lazygit/pkg/gui/types"
55
"github.com/jesseduffield/lazygit/pkg/utils"
6+
"github.com/samber/lo"
67
)
78

89
type RangeSelectMode int
@@ -85,7 +86,7 @@ func (self *ListCursor) clampValue(value int) int {
8586
clampedValue := -1
8687
length := self.getLength()
8788
if length > 0 {
88-
clampedValue = utils.Clamp(value, 0, length-1)
89+
clampedValue = lo.Clamp(value, 0, length-1)
8990
}
9091

9192
return clampedValue

pkg/gui/mergeconflicts/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"strings"
55

66
"github.com/jesseduffield/lazygit/pkg/utils"
7+
"github.com/samber/lo"
78
)
89

910
// State represents the selection state of the merge conflict context.
@@ -37,14 +38,14 @@ func (s *State) setConflictIndex(index int) {
3738
if len(s.conflicts) == 0 {
3839
s.conflictIndex = 0
3940
} else {
40-
s.conflictIndex = utils.Clamp(index, 0, len(s.conflicts)-1)
41+
s.conflictIndex = lo.Clamp(index, 0, len(s.conflicts)-1)
4142
}
4243
s.setSelectionIndex(s.selectionIndex)
4344
}
4445

4546
func (s *State) setSelectionIndex(index int) {
4647
if selections := s.availableSelections(); len(selections) != 0 {
47-
s.selectionIndex = utils.Clamp(index, 0, len(selections)-1)
48+
s.selectionIndex = lo.Clamp(index, 0, len(selections)-1)
4849
}
4950
}
5051

pkg/utils/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ func SortRange(x int, y int) (int, int) {
3939
return y, x
4040
}
4141

42-
func Clamp(x int, min int, max int) int {
43-
if x < min {
44-
return min
45-
} else if x > max {
46-
return max
47-
}
48-
return x
49-
}
50-
5142
func AsJson(i interface{}) string {
5243
bytes, _ := json.MarshalIndent(i, "", " ")
5344
return string(bytes)

0 commit comments

Comments
 (0)