1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Stop cycling hunks when reaching the end

Previously, when pressing right-arrow when the cursor is already in the last
hunk, it would jump back to the beginning of that hunk. This can be confusing if
the hunk is long, maybe the start of the hunk is already scrolled off the top of
the window, and then pressing right-arrow actually scrolls *backwards*, which is
counter-intuitive. It's better to do nothing in this case.

Same for left-arrow when the cursor is already in the first hunk, although here
the problem is not so severe (unless diff context was increased by a huge
amount, and the start of the first hunk is scrolled off the bottom of the
window).
This commit is contained in:
Stefan Haller 2023-03-12 18:31:45 +01:00
parent 79c11a0458
commit 8f164f7bc5
2 changed files with 12 additions and 2 deletions

View File

@ -149,3 +149,8 @@ func (self *Patch) LineCount() int {
}
return count
}
// Returns the number of hunks of the patch
func (self *Patch) HunkCount() int {
return len(self.hunks)
}

View File

@ -143,8 +143,13 @@ func (s *State) CycleHunk(forward bool) {
}
hunkIdx := s.patch.HunkContainingLine(s.selectedLineIdx)
start := s.patch.HunkStartIdx(hunkIdx + change)
s.selectedLineIdx = s.patch.GetNextChangeIdx(start)
if hunkIdx != -1 {
newHunkIdx := hunkIdx + change
if newHunkIdx >= 0 && newHunkIdx < s.patch.HunkCount() {
start := s.patch.HunkStartIdx(newHunkIdx)
s.selectedLineIdx = s.patch.GetNextChangeIdx(start)
}
}
}
func (s *State) CycleLine(forward bool) {