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.
This commit is contained in:
Přemysl Eric Janouch 2023-04-16 14:46:17 +02:00
parent 43363ea4bf
commit cce2b6ba51
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 27 additions and 28 deletions

55
fiv.c
View File

@ -702,40 +702,19 @@ update_files_index(void)
static void static void
change_directory_without_reload(const char *uri) change_directory_without_reload(const char *uri)
{ {
gchar *uri_duplicated = g_strdup(uri); if (g.directory) {
if (g.directory_back && !strcmp(uri, g.directory_back->data)) { // Note that this function can be passed g.directory directly.
// We're going back in history. if (!strcmp(uri, g.directory))
if (g.directory) { return;
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;
}
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. // We're on a new subpath.
g_list_free_full(g.directory_forward, g_free); g_list_free_full(g.directory_forward, g_free);
g.directory_forward = NULL; g.directory_forward = NULL;
g.directory_back = g_list_prepend(g.directory_back, g.directory); g.directory_back = g_list_prepend(g.directory_back, g.directory);
g.directory = NULL;
} }
g_free(g.directory); g.directory = g_strdup(uri);
g.directory = uri_duplicated;
} }
static void static void
@ -782,7 +761,17 @@ go_back(void)
if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box) { if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box) {
switch_to_browser_noselect(); switch_to_browser_noselect();
} else if (g.directory_back) { } 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) go_forward(void)
{ {
if (g.directory_forward) { 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) { } else if (g.uri) {
switch_to_view(); switch_to_view();
} }