diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-04-16 14:46:17 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-04-16 15:08:36 +0200 |
commit | cce2b6ba51addf1b28088174708a3c09a7f81329 (patch) | |
tree | d7d0803d5c41a34719a5c01a236068aeae293c19 | |
parent | 43363ea4bf66ab7e3cd23258ce5f0c3448a0afda (diff) | |
download | fiv-cce2b6ba51addf1b28088174708a3c09a7f81329.tar.gz fiv-cce2b6ba51addf1b28088174708a3c09a7f81329.tar.xz fiv-cce2b6ba51addf1b28088174708a3c09a7f81329.zip |
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.
-rw-r--r-- | fiv.c | 55 |
1 files changed, 27 insertions, 28 deletions
@@ -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(); } |