diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index 46098bf8..782a0567 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -2509,6 +2509,7 @@ thunar_tree_view_cursor_idle (gpointer user_data) gboolean done = FALSE; GList *lp; GList *path_as_list = NULL; + gboolean keep_path = FALSE; THUNAR_THREADS_ENTER @@ -2525,8 +2526,41 @@ THUNAR_THREADS_ENTER if (G_UNLIKELY (view->current_directory == NULL)) return TRUE; - /* get the preferred toplevel path for the current directory */ - path = thunar_tree_view_get_preferred_toplevel_path (view, view->current_directory); + + /* get active toplevel path and check if we can reuse it */ + gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, NULL); + if (path != NULL) + { + if (gtk_tree_path_get_depth (path) != 1) + while (gtk_tree_path_get_depth (path) > 1) + gtk_tree_path_up (path); + // check if path valid? + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->model), &iter, path)) + { + /* lookup file for the toplevel item */ + gtk_tree_model_get (GTK_TREE_MODEL (view->model), &iter, THUNAR_TREE_MODEL_COLUMN_FILE, &file, -1); + if (file) + { + /* check if the toplevel file is an ancestor */ + if (thunar_file_is_ancestor (view->current_directory, file)) + keep_path = TRUE; + + g_object_unref (file); + } + } + + if (!keep_path) + { + gtk_tree_path_free (path); + path = NULL; + } + } + + + /* fallback to preferred toplevel path for the current directory */ + if (path == NULL) + path = thunar_tree_view_get_preferred_toplevel_path (view, view->current_directory); /* fallback to a newly created root node */ if (path == NULL)