mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-08 22:36:49 +02:00
Refactor: extract function clampLineIdx
And reimplement using lo.Clamp instead of comparing manually.
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// State represents the current state of the patch explorer context i.e. when
|
// State represents the current state of the patch explorer context i.e. when
|
||||||
@ -177,15 +178,13 @@ func (s *State) SelectLine(newSelectedLineIdx int) {
|
|||||||
s.selectLineWithoutRangeCheck(newSelectedLineIdx)
|
s.selectLineWithoutRangeCheck(newSelectedLineIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This just moves the cursor without caring about range select
|
func (s *State) clampLineIdx(lineIdx int) int {
|
||||||
func (s *State) selectLineWithoutRangeCheck(newSelectedLineIdx int) {
|
return lo.Clamp(lineIdx, 0, len(s.patchLineIndices)-1)
|
||||||
if newSelectedLineIdx < 0 {
|
|
||||||
newSelectedLineIdx = 0
|
|
||||||
} else if newSelectedLineIdx > len(s.patchLineIndices)-1 {
|
|
||||||
newSelectedLineIdx = len(s.patchLineIndices) - 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.selectedLineIdx = newSelectedLineIdx
|
// This just moves the cursor without caring about range select
|
||||||
|
func (s *State) selectLineWithoutRangeCheck(newSelectedLineIdx int) {
|
||||||
|
s.selectedLineIdx = s.clampLineIdx(newSelectedLineIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) SelectNewLineForRange(newSelectedLineIdx int) {
|
func (s *State) SelectNewLineForRange(newSelectedLineIdx int) {
|
||||||
|
Reference in New Issue
Block a user