From 2e31516f34f1228cc16563db4b9093d4425fa7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 4 Oct 2021 22:16:52 +0200 Subject: [PATCH] Enable jumping back in main view (#1138) Allow going back to the previously selected commit after jumping to its parent. Fixes #628 [tk: added test] --- src/main.c | 16 +++++++++++++++- test/main/goto-test | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index d6b80175e..54ca950c3 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,8 @@ DEFINE_ALLOCATOR(realloc_reflogs, char *, 32) +static struct view_history main_view_history = { 0 }; + bool main_status_exists(struct view *view, enum line_type type) { @@ -572,7 +574,19 @@ main_request(struct view *view, enum request request, struct line *line) break; case REQ_PARENT: - goto_id(view, "%(commit)^", true, false); + if (push_view_history_state(&main_view_history, &view->pos, NULL)) { + goto_id(view, "%(commit)^", true, false); + } else { + report("Failed to save current view state"); + } + break; + + case REQ_BACK: + if (pop_view_history_state(&main_view_history, &view->pos, NULL)) { + redraw_view(view); + } else { + report("Already at start of history"); + } break; case REQ_MOVE_NEXT_MERGE: diff --git a/test/main/goto-test b/test/main/goto-test index 2fb28a10d..4ae5ec6e7 100755 --- a/test/main/goto-test +++ b/test/main/goto-test @@ -15,6 +15,10 @@ steps ' :save-display commit-1.screen :parent :save-display commit-2.screen + :back + :save-display commit-1-back.screen + :parent + :save-display commit-2-again.screen :parent :save-display commit-5.screen :parent @@ -39,6 +43,18 @@ assert_equals 'commit-1.screen' <