"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: fix log view 'd' keymap when less than nlines/2 from the last commit
To:
gameoftrees@openbsd.org
Date:
Wed, 10 Aug 2022 00:49:27 +1000

Download raw body.

Thread
We incorrectly reassign when we should be incrementing the selected
index. As a result, if the currently selected commit is less than
nlines/2 from the last commit and we use 'd' to scroll down half
a page, we jump up!

repro:
  $ tog  # 80x24 in got.git
  G
  5k
  d
  *selection moves up 6 lines instead of moving to the last commit!*

Relatedly, I've simplified the page down logic a bit so that if the last
commit is already on screen when in a hsplit, we move the selection
cursor down rather than scroll. This required accounting for the border
when drawing commits in a horizontal split, which was previously missed,
to ensure last_displayed_entry->idx is correct.

ok?

-----------------------------------------------
commit 99cad5fe74c15ae67c4c36feb5219ac7db6bce16 (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Tue Aug  9 14:43:17 2022 UTC
 
 tog: fix log 'd' keymap when last commit is displayed
 
 When at the end of the log view, add--don't assign--the page down value to the
 selected index so we don't jump up when the user expects tog to scroll down.
 While here, rework log page down logic for a smoother UX in horizontal split
 mode by moving the selection cursor down rather than scrolling when 'd' or 'f'
 is entered if the last commit is already on screen.
 
diff 3ff00eade6c3b17a852658c28502edbfc83ef25b 99cad5fe74c15ae67c4c36feb5219ac7db6bce16
commit - 3ff00eade6c3b17a852658c28502edbfc83ef25b
commit + 99cad5fe74c15ae67c4c36feb5219ac7db6bce16
blob - 79bd77c80f7773fd9a6bd7e5f5cfeb69ff90f91c
blob + 9a96a04f56edb048866ce0590cd7e00ebdbb8937
--- tog/tog.c
+++ tog/tog.c
@@ -2238,7 +2238,7 @@ draw_commits(struct tog_view *view)
 	const struct got_error *err = NULL;
 	struct tog_log_view_state *s = &view->state.log;
 	struct commit_queue_entry *entry = s->selected_entry;
-	const int limit = view->nlines;
+	int limit = view->nlines;
 	int width;
 	int ncommits, author_cols = 4;
 	char *id_str = NULL, *header = NULL, *ncommits_str = NULL;
@@ -2247,6 +2247,9 @@ draw_commits(struct tog_view *view)
 	struct tog_color *tc;
 	static const size_t date_display_cols = 12;
 
+	if (view_is_hsplit_top(view))
+		--limit;  /* account for border */
+
 	if (s->selected_entry &&
 	    !(view->searching && view->search_next_done == 0)) {
 		struct got_reflist_head *refs;
@@ -3161,15 +3164,8 @@ static const struct got_error *
 log_move_cursor_down(struct tog_view *view, int page)
 {
 	struct tog_log_view_state	*s = &view->state.log;
-	struct commit_queue_entry	*first;
 	const struct got_error		*err = NULL;
 
-	first = s->first_displayed_entry;
-	if (first == NULL) {
-		view->count = 0;
-		return NULL;
-	}
-
 	if (s->thread_args.log_complete &&
 	    s->selected_entry->idx >= s->commits.ncommits - 1)
 		return NULL;
@@ -3192,13 +3188,11 @@ log_move_cursor_down(struct tog_view *view, int page)
 			    s->commits.ncommits - s->selected_entry->idx - 1));
 		s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1);
 	} else {
-		err = log_scroll_down(view, page);
-		if (err)
-			return err;
-		if (first == s->first_displayed_entry && s->selected <
-		    MIN(view->nlines - 2, s->commits.ncommits - 1)) {
-			s->selected = MIN(s->commits.ncommits - 1, page);
-		}
+		if (s->last_displayed_entry->idx == s->commits.ncommits - 1)
+			s->selected += MIN(page,
+			    s->commits.ncommits - s->selected_entry->idx - 1);
+		else
+			err = log_scroll_down(view, page);
 	}
 	if (err)
 		return err;

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68