[nautilus] list-base: Select first search result as soon as possible



commit 0e704e21cd3dddec44268295595724ca41e24822
Author: Corey Berla <corey berla me>
Date:   Sat Sep 17 08:54:45 2022 +0000

    list-base: Select first search result as soon as possible
    
    We used to select the first search result as soon as it arives,
    in order to allow keyboard shortcuts to take effect on it. This
    makes search more efficient to use with keyboard.
    
    Prior to the gtk4 port (and the introduction of list-base,
    canvas view and list view set the selection directly in `select_first`
    through `icon_set_selected` and `gtk_tree_selection_select_iter`.
    
    After the port to gtk4, list-base used the existing function
    `nautilus_view_set_selection` which seemed to work, except
    `nautilus_files_view_set_selection` only actually sets the selection
    when the view is not loading.  In the meantime, it puts the selection
    is a pending_selection to be set when the loading is complete.
    
    This causes problems for search because loading generally takes
    longer to complete in a search, and the user will have to wait
    until the search is complete for the item to be selected.
    As a matter of fact, the *only* time that select_first is used
    is during a search (which was the original intention of the function
    when introduced in 50711e28ba4d4c971a812a0bdef0c30516141f4e).
    
    There's no need to add further complexity, beyond what the
    GtkSelectionModel already provides.  Just as `real_select_all`
    simples calls `gtk_selection_model_select_all`, make
    `real_select_first` call `gtk_selection_model_select_item`.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2481

 src/nautilus-list-base.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index f4673b9d3..c1f85e6d1 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -1506,18 +1506,8 @@ real_select_first (NautilusFilesView *files_view)
 {
     NautilusListBase *self = NAUTILUS_LIST_BASE (files_view);
     NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
-    g_autoptr (NautilusViewItem) item = NULL;
-    NautilusFile *file;
-    g_autoptr (GList) selection = NULL;
 
-    item = get_view_item (G_LIST_MODEL (priv->model), 0);
-    if (item == NULL)
-    {
-        return;
-    }
-    file = nautilus_view_item_get_file (item);
-    selection = g_list_prepend (selection, file);
-    nautilus_view_set_selection (NAUTILUS_VIEW (files_view), selection);
+    gtk_selection_model_select_item (GTK_SELECTION_MODEL (priv->model), 0, TRUE);
 }
 
 static GdkRectangle *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]