summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Berla <corey@berla.me>2022-10-25 13:22:01 -0700
committerAntónio Fernandes <antoniof@gnome.org>2022-12-20 07:27:09 +0000
commit1034ab5bbd9a2e27967772ca47f1c808cf297203 (patch)
tree9ea59a5d88071d79075d3db3166b3f129d13bd8e
parent26c2ab292ac9196758114575597067205192c015 (diff)
downloadnautilus-1034ab5bbd9a2e27967772ca47f1c808cf297203.tar.gz
list-base: Don't modify selection model's internal bitset
In real_set_selection, we call gtk_selection_model_get_selection() to be able to efficiently update the selection (we don't care about unselected items that we aren't going to select). That bitset, per the documentation, shouldn't be modified. This bug (which made this function effective useless) went unnoticed because we were setting the selection elsewhere by poking the internals of the listbase in set_focus_item. We don't want to do that anymore, and this bug became apparent. Make a copy of the bitset, and rename the existing bitsets to clarify what we are doing. Also, set the selection after setting the focus just in case that ever conflicts in the future.
-rw-r--r--src/nautilus-list-base.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index d19bb65f6..77c27325b 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -1219,17 +1219,20 @@ real_set_selection (NautilusFilesView *files_view,
g_autoptr (GQueue) selection_files = NULL;
g_autoptr (GQueue) selection_items = NULL;
g_autoptr (GtkBitset) update_set = NULL;
- g_autoptr (GtkBitset) selection_set = NULL;
+ g_autoptr (GtkBitset) new_selection_set = NULL;
+ g_autoptr (GtkBitset) old_selection_set = NULL;
- update_set = gtk_selection_model_get_selection (GTK_SELECTION_MODEL (priv->model));
- selection_set = gtk_bitset_new_empty ();
+ old_selection_set = gtk_selection_model_get_selection (GTK_SELECTION_MODEL (priv->model));
+ /* We aren't allowed to modify the actual selection bitset */
+ update_set = gtk_bitset_copy (old_selection_set);
+ new_selection_set = gtk_bitset_new_empty ();
/* Convert file list into set of model indices */
selection_files = convert_glist_to_queue (selection);
selection_items = nautilus_view_model_get_items_from_files (priv->model, selection_files);
for (GList *l = g_queue_peek_head_link (selection_items); l != NULL; l = l->next)
{
- gtk_bitset_add (selection_set,
+ gtk_bitset_add (new_selection_set,
nautilus_view_model_get_index (priv->model, l->data));
}
@@ -1240,9 +1243,9 @@ real_set_selection (NautilusFilesView *files_view,
set_focus_item (self, item);
}
- gtk_bitset_union (update_set, selection_set);
+ gtk_bitset_union (update_set, new_selection_set);
gtk_selection_model_set_selection (GTK_SELECTION_MODEL (priv->model),
- selection_set,
+ new_selection_set,
update_set);
}