From cce2b6ba51addf1b28088174708a3c09a7f81329 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 16 Apr 2023 14:46:17 +0200 Subject: Fix history behaviour When starting in A/B, then manually going up to A, and back down to A/B, going back in history to A was impossible, because it would actually end up being a /forward/ entry. --- fiv.c | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/fiv.c b/fiv.c index c28fd26..0f7e277 100644 --- a/fiv.c +++ b/fiv.c @@ -702,40 +702,19 @@ update_files_index(void) static void change_directory_without_reload(const char *uri) { - gchar *uri_duplicated = g_strdup(uri); - if (g.directory_back && !strcmp(uri, g.directory_back->data)) { - // We're going back in history. - if (g.directory) { - g.directory_forward = - g_list_prepend(g.directory_forward, g.directory); - g.directory = NULL; - } - - GList *link = g.directory_back; - g.directory_back = g_list_remove_link(g.directory_back, link); - g_list_free_full(link, g_free); - } else if (g.directory_forward && !strcmp(uri, g.directory_forward->data)) { - // We're going forward in history. - if (g.directory) { - g.directory_back = - g_list_prepend(g.directory_back, g.directory); - g.directory = NULL; - } + if (g.directory) { + // Note that this function can be passed g.directory directly. + if (!strcmp(uri, g.directory)) + return; - GList *link = g.directory_forward; - g.directory_forward = g_list_remove_link(g.directory_forward, link); - g_list_free_full(link, g_free); - } else if (g.directory && strcmp(uri, g.directory)) { // We're on a new subpath. g_list_free_full(g.directory_forward, g_free); g.directory_forward = NULL; g.directory_back = g_list_prepend(g.directory_back, g.directory); - g.directory = NULL; } - g_free(g.directory); - g.directory = uri_duplicated; + g.directory = g_strdup(uri); } static void @@ -782,7 +761,17 @@ go_back(void) if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box) { switch_to_browser_noselect(); } else if (g.directory_back) { - load_directory(g.directory_back->data); + if (g.directory) + g.directory_forward = + g_list_prepend(g.directory_forward, g.directory); + + const gchar *uri = g.directory = g.directory_back->data; + + GList *link = g.directory_back; + g.directory_back = g_list_remove_link(g.directory_back, link); + g_list_free(link); + + load_directory(uri); } } @@ -790,7 +779,17 @@ static void go_forward(void) { if (g.directory_forward) { - load_directory(g.directory_forward->data); + if (g.directory) + g.directory_back = + g_list_prepend(g.directory_back, g.directory); + + const gchar *uri = g.directory = g.directory_forward->data; + + GList *link = g.directory_forward; + g.directory_forward = g_list_remove_link(g.directory_forward, link); + g_list_free(link); + + load_directory(uri); } else if (g.uri) { switch_to_view(); } -- cgit v1.2.3-70-g09d2