summaryrefslogtreecommitdiffstats
path: root/pkg/gui/patch_exploring
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-03-12 18:31:45 +0100
committerStefan Haller <stefan@haller-berlin.de>2023-08-15 11:40:40 +0200
commit8f164f7bc536ca711e531d49f96348fbae54b860 (patch)
tree9c598b4718625ee80e3cac7afff999317105a21d /pkg/gui/patch_exploring
parent79c11a045886426482e473cc860b7fa7e4dbd1e6 (diff)
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).
Diffstat (limited to 'pkg/gui/patch_exploring')
-rw-r--r--pkg/gui/patch_exploring/state.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/pkg/gui/patch_exploring/state.go b/pkg/gui/patch_exploring/state.go
index 356bff4f4..1c82d59cb 100644
--- a/pkg/gui/patch_exploring/state.go
+++ b/pkg/gui/patch_exploring/state.go
@@ -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) {