From fa9a00e1e3f746ebd2090d413e9dea759d8cf6ca Mon Sep 17 00:00:00 2001 From: Theo Linkspfeifer Date: Wed, 18 Mar 2020 23:36:43 +0100 Subject: [PATCH] Use tre-view toplevel path of the cursor, if available in order to prevent jumping (Bug #16024) Co-authored-by: Alexander Schwinn --- thunar/thunar-tree-view.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index e3fc8947..a7820eee 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -2525,8 +2525,35 @@ 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); + + 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) == FALSE) + { + gtk_tree_path_free (path); + path = NULL; + } + g_object_unref (file); + } + } + } + + + /* 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) -- 2.25.0