Commit 31607d6c745643159f3f25eee25189cf3b5d8cc2

Stefan Sperling 2018-08-18T13:27:14

allow backspace to cycle views backwards in tog

diff --git a/tog/tog.1 b/tog/tog.1
index 53ede1f..3f2551b 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -62,6 +62,9 @@ Quit the view which is in focus.
 .It Cm Tab
 Switch focus to the next view.
 Cycles through all open views.
+.It Cm Backspace
+Switch focus to the previous view.
+Cycles through all open views.
 .El
 .Pp
 Global options must precede the command name, and are as follows:
@@ -130,7 +133,7 @@ are as follows:
 .Bl -tag -width Ds
 .It Cm Down-arrow, j, Page-down, Space
 Scroll down.
-.It Cm Up-arrow, k, Page-up, Backspace
+.It Cm Up-arrow, k, Page-up
 Scroll up.
 .El
 .It Cm blame [ Fl c Ar commit ] [ Fl r Ar repository-path ] Ar path
@@ -142,7 +145,7 @@ are as follows:
 .Bl -tag -width Ds
 .It Cm Down-arrow, j, Page-down, Space
 Move the selection cursor down.
-.It Cm Up-arrow, k, Page-up, Backspace
+.It Cm Up-arrow, k, Page-up
 Move the selection cursor up.
 .It Cm Enter
 Switch to the
@@ -199,7 +202,7 @@ view for the currently selected file.
 Switch to the
 .Cm log
 view for the currently selected tree entry.
-.It Cm Backspace
+.It Cm Left-arrow
 Move back to the parent directory.
 .It Cm i
 Show the object IDs for all objects displayed in the
diff --git a/tog/tog.c b/tog/tog.c
index a69b40e..d99b301 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -343,7 +343,7 @@ view_input(struct tog_view **new, struct tog_view **dead,
     struct tog_view_list_head *views)
 {
 	const struct got_error *err = NULL;
-	struct tog_view *next;
+	struct tog_view *next, *prev;
 	int ch;
 
 	*new = NULL;
@@ -362,6 +362,13 @@ view_input(struct tog_view **new, struct tog_view **dead,
 			else
 				*focus = TAILQ_FIRST(views);
 			break;
+		case KEY_BACKSPACE:
+			prev = TAILQ_PREV(view, tog_view_list_head, entry);
+			if (prev)
+				*focus = prev;
+			else
+				*focus = TAILQ_LAST(views, tog_view_list_head);
+			break;
 		case 'q':
 			err = view->input(new, dead, view, ch);
 			*dead = view;
@@ -1438,7 +1445,6 @@ input_diff_view(struct tog_view **new, struct tog_view **dead,
 				s->first_displayed_line--;
 			break;
 		case KEY_PPAGE:
-		case KEY_BACKSPACE:
 			i = 0;
 			while (i++ < view->nlines - 1 &&
 			    s->first_displayed_line > 1)
@@ -2019,7 +2025,6 @@ input_blame_view(struct tog_view **new_view, struct tog_view **dead_view,
 				s->first_displayed_line--;
 			break;
 		case KEY_PPAGE:
-		case KEY_BACKSPACE:
 			if (s->first_displayed_line == 1) {
 				s->selected_line = 1;
 				break;
@@ -2687,7 +2692,7 @@ input_tree_view(struct tog_view **new_view, struct tog_view **dead_view,
 		case '\r':
 			if (s->selected_entry == NULL) {
 				struct tog_parent_tree *parent;
-		case KEY_BACKSPACE:
+		case KEY_LEFT:
 				/* user selected '..' */
 				if (s->tree == s->root)
 					break;