Commit 912a3f7945204384e4aa755c41dd4e89a855ef38

Jasper Lievisse Adriaanse 2021-08-30T17:49:33

tog: add support for navigating to first/last item of log and diff views The keybindings that we settled on are Home, Ctrl-u and g to go to the first item and End, G to go to the last. This resembles those commonly found elsewhere, eg vi/less. discussed with and ok stsp

diff --git a/tog/tog.1 b/tog/tog.1
index e22d907..3d45c56 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -108,6 +108,12 @@ Move the selection cursor up.
 Move the selection cursor down one page.
 .It Cm Page-up, Ctrl+b
 Move the selection cursor up one page.
+.It Cm Home, g, Ctrl-u
+Move the cursor to the newest commit.
+.It Cm End, G
+Move the cursor to the oldest commit.
+This will iterate over all commit objects in the repository and may take
+a long time depending on the size of the repository.
 .It Cm Enter, Space
 Open a
 .Cm diff
@@ -210,6 +216,10 @@ Scroll up.
 Scroll down one page.
 .It Cm Page-up, Ctrl+b
 Scroll up one page.
+.It Cm Home, g, Ctrl-u
+Scroll to the top of the view.
+.It Cm End, G
+Scroll to the bottom of the view.
 .It Cm \&[
 Reduce the amount of diff context lines.
 .It Cm \&]
diff --git a/tog/tog.c b/tog/tog.c
index fc51be8..f19156f 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2406,6 +2406,16 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
 			log_scroll_up(s, 1);
 		select_commit(s);
 		break;
+	case 'g':
+	case CTRL('u'):
+	case KEY_HOME:
+		if (s->first_displayed_entry == NULL)
+			break;
+
+		s->selected = 0;
+		log_scroll_up(s, s->commits.ncommits);
+		select_commit(s);
+		break;
 	case KEY_PPAGE:
 	case CTRL('b'):
 		if (s->first_displayed_entry == NULL)
@@ -2432,6 +2442,25 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
 		}
 		select_commit(s);
 		break;
+	case 'G':
+	case KEY_END: {
+		/* We don't know yet how many commits, so we're forced to
+		 * traverse them all. */
+		while (1) {
+			if (s->thread_args.log_complete)
+				break;
+
+			s->thread_args.commits_needed++;
+			err = trigger_log_thread(view, 1);
+			if (err)
+				return err;
+		}
+
+		log_scroll_down(view, s->commits.ncommits);
+		s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1);
+		select_commit(s);
+		break;
+	}
 	case KEY_NPAGE:
 	case CTRL('f'): {
 		struct commit_queue_entry *first;
@@ -3641,6 +3670,19 @@ input_diff_view(struct tog_view **new_view, struct tog_view *view, int ch)
 		diff_view_indicate_progress(view);
 		err = create_diff(s);
 		break;
+	case 'g':
+	case CTRL('u'):
+	case KEY_HOME:
+		s->first_displayed_line = 1;
+		break;
+	case 'G':
+	case KEY_END:
+		if (s->eof)
+			break;
+
+		s->first_displayed_line = (s->nlines - view->nlines) + 2;
+		s->eof = 1;
+		break;
 	case 'k':
 	case KEY_UP:
 		if (s->first_displayed_line > 1)