Commit Diff


commit - 0ed6bc9021ade98ba6b1574847e83aec980a398e
commit + d627976f5ceada12169aa74630bbc0fd9ce071b7
blob - a752780caccc9b9007daf5bc95cf05bde851090c
blob + 667bfe283076f37b6cb5690da6b2a98d9aae516a
--- tog/tog.1
+++ tog/tog.1
@@ -112,6 +112,18 @@ N increments (default: 1).
 Go to line N in the view (default: last line).
 .It Cm g
 Go to line N in the view (default: first line).
+.It Cm Right-arrow, l
+Scroll view to the right N increments (default: 1).
+.br
+Output moves left on the screen.
+.It Cm Left-arrow, h
+Scroll view to the left N increments (default: 1).
+.br
+Output moves right on the screen.
+.It Cm $
+Scroll view to the rightmost position.
+.It Cm 0
+Scroll view left to the start of the line.
 .El
 .Pp
 The commands for
@@ -145,18 +157,6 @@ are as follows (N denotes optional prefixed count modi
 Move the selection cursor down N lines (default: 1).
 .It Cm Up-arrow, k, <, Comma, Ctrl-p
 Move the selection cursor up N lines (default: 1).
-.It Cm Right-arrow, l
-Scroll log message field to the right N increments (default: 1).
-.br
-Log message moves left on the screen.
-.It Cm Left-arrow, h
-Scroll log message field to the left N increments (default: 1).
-.br
-Log message moves right on the screen.
-.It Cm $
-Scroll log message field to the rightmost position.
-.It Cm 0
-Scroll log message field to the leftmost position.
 .It Cm Page-down, Space, Ctrl+f, f
 Move the selection cursor down N pages (default: 1).
 .It Cm Page-up, Ctrl+b, b
@@ -313,18 +313,6 @@ detected.
 Scroll down N lines (default: 1).
 .It Cm Up-arrow, k, Ctrl-p
 Scroll up N lines (default: 1).
-.It Cm Right-arrow, l
-Scroll view to the right N increments (default: 1).
-.br
-Diff output moves left on the screen.
-.It Cm Left-arrow, h
-Scroll view to the left N increments (default: 1).
-.br
-Diff output moves right on the screen.
-.It Cm $
-Scroll view to the rightmost position.
-.It Cm 0
-Scroll view left to the start of the line.
 .It Cm Page-down, Space, Ctrl+f, f
 Scroll down N pages (default: 1).
 .It Cm Page-up, Ctrl+b, b
@@ -430,18 +418,6 @@ are as follows (N denotes optional prefixed count modi
 Move the selection cursor down N pages (default: 1).
 .It Cm Up-arrow, k, Ctrl-p
 Move the selection cursor up N pages (default: 1).
-.It Cm Right-arrow, l
-Scroll view to the right N increments (default: 1).
-.br
-File output moves left on the screen.
-.It Cm Left-arrow, h
-Scroll view to the left N increments (default: 1).
-.br
-File output moves right on the screen.
-.It Cm $
-Scroll view to the rightmost position.
-.It Cm 0
-Scroll view left to the start of the line.
 .It Cm Page-down, Space, Ctrl+f, f
 Move the selection cursor down N pages (default: 1).
 .It Cm Page-up, Ctrl+b, b
blob - 73869bfa87df9af7a68e8ec4c44690f950d74ccb
blob + a6351da680ffacc2f47bf1a42b494d77af0b4a3a
--- tog/tog.c
+++ tog/tog.c
@@ -3689,7 +3689,37 @@ log_goto_line(struct tog_view *view, int nlines)
 
 	select_commit(s);
 	return NULL;
+
+}
+
+static void
+horizontal_scroll_input(struct tog_view *view, int ch)
+{
 
+	switch (ch) {
+	case KEY_LEFT:
+	case 'h':
+		view->x -= MIN(view->x, 2);
+		if (view->x <= 0)
+			view->count = 0;
+		break;
+	case KEY_RIGHT:
+	case 'l':
+		if (view->x + view->ncols / 2 < view->maxx)
+			view->x += 2;
+		else
+			view->count = 0;
+		break;
+	case '0':
+		view->x = 0;
+		break;
+	case '$':
+		view->x = MAX(view->maxx - view->ncols / 2, 0);
+		view->count = 0;
+		break;
+	default:
+		break;
+	}
 }
 
 static const struct got_error *
@@ -3725,24 +3755,12 @@ input_log_view(struct tog_view **new_view, struct tog_
 		s->quit = 1;
 		break;
 	case '0':
-		view->x = 0;
-		break;
 	case '$':
-		view->x = MAX(view->maxx - view->ncols / 2, 0);
-		view->count = 0;
-		break;
 	case KEY_RIGHT:
 	case 'l':
-		if (view->x + view->ncols / 2 < view->maxx)
-			view->x += 2;  /* move two columns right */
-		else
-			view->count = 0;
-		break;
 	case KEY_LEFT:
 	case 'h':
-		view->x -= MIN(view->x, 2);  /* move two columns back */
-		if (view->x <= 0)
-			view->count = 0;
+		horizontal_scroll_input(view, ch);
 		break;
 	case 'k':
 	case KEY_UP:
@@ -5299,24 +5317,12 @@ input_diff_view(struct tog_view **new_view, struct tog
 
 	switch (ch) {
 	case '0':
-		view->x = 0;
-		break;
 	case '$':
-		view->x = MAX(view->maxx - view->ncols / 3, 0);
-		view->count = 0;
-		break;
 	case KEY_RIGHT:
 	case 'l':
-		if (view->x + view->ncols / 3 < view->maxx)
-			view->x += 2;  /* move two columns right */
-		else
-			view->count = 0;
-		break;
 	case KEY_LEFT:
 	case 'h':
-		view->x -= MIN(view->x, 2);  /* move two columns back */
-		if (view->x <= 0)
-			view->count = 0;
+		horizontal_scroll_input(view, ch);
 		break;
 	case 'a':
 	case 'w':
@@ -6324,24 +6330,12 @@ input_blame_view(struct tog_view **new_view, struct to
 
 	switch (ch) {
 	case '0':
-		view->x = 0;
-		break;
 	case '$':
-		view->x = MAX(view->maxx - view->ncols / 3, 0);
-		view->count = 0;
-		break;
 	case KEY_RIGHT:
 	case 'l':
-		if (view->x + view->ncols / 3 < view->maxx)
-			view->x += 2;  /* move two columns right */
-		else
-			view->count = 0;
-		break;
 	case KEY_LEFT:
 	case 'h':
-		view->x -= MIN(view->x, 2);  /* move two columns back */
-		if (view->x <= 0)
-			view->count = 0;
+		horizontal_scroll_input(view, ch);
 		break;
 	case 'q':
 		s->done = 1;
@@ -6779,7 +6773,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 	wchar_t *wline;
 	char *index = NULL;
 	struct tog_color *tc;
-	int width, n, nentries, i = 1;
+	int width, n, nentries, scrollx, i = 1;
 	int limit = view->nlines;
 
 	s->ndisplayed = 0;
@@ -6856,6 +6850,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 		te = s->first_displayed_entry;
 	}
 
+	view->maxx = 0;
 	for (i = got_tree_entry_get_index(te); i < nentries; i++) {
 		char *line = NULL, *id_str = NULL, *link_target = NULL;
 		const char *modestr = "";
@@ -6902,12 +6897,23 @@ draw_tree_entries(struct tog_view *view, const char *p
 		}
 		free(id_str);
 		free(link_target);
-		err = format_line(&wline, &width, NULL, line, 0, view->ncols,
-		    0, 0);
+
+		/* use full line width to determine view->maxx */
+		err = format_line(&wline, &width, NULL, line, 0, INT_MAX, 0, 0);
 		if (err) {
 			free(line);
 			break;
 		}
+		view->maxx = MAX(view->maxx, width);
+		free(wline);
+		wline = NULL;
+
+		err = format_line(&wline, &width, &scrollx, line, view->x,
+		    view->ncols, 0, 0);
+		if (err) {
+			free(line);
+			break;
+		}
 		if (n == s->selected) {
 			if (view->focussed)
 				wstandout(view->window);
@@ -6917,7 +6923,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 		if (tc)
 			wattr_on(view->window,
 			    COLOR_PAIR(tc->colorpair), NULL);
-		waddwstr(view->window, wline);
+		waddwstr(view->window, &wline[scrollx]);
 		if (tc)
 			wattr_off(view->window,
 			    COLOR_PAIR(tc->colorpair), NULL);
@@ -7391,6 +7397,14 @@ input_tree_view(struct tog_view **new_view, struct tog
 		return tree_goto_line(view, nscroll);
 
 	switch (ch) {
+	case '0':
+	case '$':
+	case KEY_RIGHT:
+	case 'l':
+	case KEY_LEFT:
+	case 'h':
+		horizontal_scroll_input(view, ch);
+		break;
 	case 'i':
 		s->show_ids = !s->show_ids;
 		view->count = 0;
@@ -8302,24 +8316,12 @@ input_ref_view(struct tog_view **new_view, struct tog_
 
 	switch (ch) {
 	case '0':
-		view->x = 0;
-		break;
 	case '$':
-		view->x = MAX(view->maxx - view->ncols / 2, 0);
-		view->count = 0;
-		break;
 	case KEY_RIGHT:
 	case 'l':
-		if (view->x + view->ncols / 2 < view->maxx)
-			view->x += 2;
-		else
-			view->count = 0;
-		break;
 	case KEY_LEFT:
 	case 'h':
-		view->x -= MIN(view->x, 2);
-		if (view->x <= 0)
-			view->count = 0;
+		horizontal_scroll_input(view, ch);
 		break;
 	case 'i':
 		s->show_ids = !s->show_ids;
@@ -8933,24 +8935,12 @@ input_help_view(struct tog_view **new_view, struct tog
 
 	switch (ch) {
 	case '0':
-		view->x = 0;
-		break;
 	case '$':
-		view->x = MAX(view->maxx - view->ncols / 3, 0);
-		view->count = 0;
-		break;
 	case KEY_RIGHT:
 	case 'l':
-		if (view->x + view->ncols / 3 < view->maxx)
-			view->x += 2;
-		else
-			view->count = 0;
-		break;
 	case KEY_LEFT:
 	case 'h':
-		view->x -= MIN(view->x, 2);
-		if (view->x <= 0)
-			view->count = 0;
+		horizontal_scroll_input(view, ch);
 		break;
 	case 'g':
 	case KEY_HOME: