From 09f4546d50fa86a61e3e29a900ff5026303e544a Mon Sep 17 00:00:00 2001 From: Gary Li Date: Sun, 12 May 2024 18:10:15 -0400 Subject: [PATCH] files-view: Check model empty selection after delayed signals emitted When the user enter keystrokes to search, the first item sometimes gets deselected before being reselected. This is due to the gtk_bitset_is_empty check in display_pending_files, which occurs before the delayed clear signals are emitted. On the first display_pending_files call after the keystroke, there may still be a non-empty selection. Since the check happens before clear is emitted, we errorneously believe there was a selection so we do not select first until display_pending_files is called again. Move the no_selection bitset check to after we have emitted the delayed clear signal. Ensure there is at least 1 item in the model before we select the 0th index. Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/3420 --- src/nautilus-files-view.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index dd6251eaa..25638d60c 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -774,7 +774,10 @@ static void nautilus_files_view_select_first (NautilusFilesView *self) { NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (self); - nautilus_list_base_set_cursor (priv->list_base, 0, TRUE, TRUE); + if (g_list_model_get_n_items (G_LIST_MODEL (priv->model)) > 0) + { + nautilus_list_base_set_cursor (priv->list_base, 0, TRUE, TRUE); + } } static void @@ -4451,11 +4454,14 @@ static void display_pending_files (NautilusFilesView *view) { NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view); - g_autoptr (GtkBitset) selection = gtk_selection_model_get_selection (GTK_SELECTION_MODEL (priv->model)); - gboolean no_selection = gtk_bitset_is_empty (selection); + g_autoptr (GtkBitset) selection = NULL; + gboolean no_selection = FALSE; search_transition_emit_delayed_signals_if_pending (view); + selection = gtk_selection_model_get_selection (GTK_SELECTION_MODEL (priv->model)); + no_selection = gtk_bitset_is_empty (selection); + process_pending_files (view); if (no_selection &&