diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c index cfa2f2b843..82c6444cff 100644 --- a/gtk/gtklistitemmanager.c +++ b/gtk/gtklistitemmanager.c @@ -117,7 +117,6 @@ gtk_list_item_change_release (GtkListItemChange *change, if (!g_hash_table_replace (change->deleted_items, gtk_list_item_base_get_item (GTK_LIST_ITEM_BASE (widget)), widget)) { g_warning ("Duplicate item detected in list. Picking one randomly."); - gtk_list_item_change_recycle (change, widget); } } @@ -968,10 +967,26 @@ gtk_list_item_manager_add_items (GtkListItemManager *self, if (section != NULL && section->type == GTK_LIST_TILE_HEADER) { + guint start, end; + GtkListTile *footer = gtk_list_tile_get_footer (self, section); + GtkListTile *previous_footer = gtk_list_tile_get_previous_skip (section); + + gtk_section_model_get_section (GTK_SECTION_MODEL (self->model), position, &start, &end); + + if (previous_footer != NULL && previous_footer->type == GTK_LIST_TILE_FOOTER && + position > start && position < end) + { + gtk_list_item_change_clear_header (change, §ion->widget); + gtk_list_tile_set_type (section, GTK_LIST_TILE_REMOVED); + gtk_list_tile_set_type (previous_footer, GTK_LIST_TILE_REMOVED); + + section = gtk_list_tile_get_header (self, previous_footer); + } + gtk_list_item_change_clear_header (change, §ion->widget); gtk_list_tile_set_type (section, GTK_LIST_TILE_UNMATCHED_HEADER); - gtk_list_tile_set_type (gtk_list_tile_get_footer (self, section), + gtk_list_tile_set_type (footer, GTK_LIST_TILE_UNMATCHED_FOOTER); } } @@ -1610,7 +1625,7 @@ gtk_list_item_manager_model_sections_changed_cb (GListModel *model, gtk_list_item_change_clear_header (&change, &header->widget); gtk_list_tile_set_type (header, GTK_LIST_TILE_UNMATCHED_HEADER); - n_items -= MIN (n_items, position - offset); + n_items += offset; while (n_items > 0) { switch (tile->type) diff --git a/testsuite/gtk/listitemmanager.c b/testsuite/gtk/listitemmanager.c index e11e3f85e0..07486e9e99 100644 --- a/testsuite/gtk/listitemmanager.c +++ b/testsuite/gtk/listitemmanager.c @@ -433,7 +433,7 @@ test_exhaustive (void) gboolean add = FALSE, remove = FALSE; guint position, n_items; - switch (g_test_rand_int_range (0, 6)) + switch (g_test_rand_int_range (0, 7)) { case 0: if (g_test_verbose ()) @@ -483,6 +483,34 @@ test_exhaustive (void) } break; + case 6: + { + n_items = g_list_model_get_n_items (G_LIST_MODEL (store)); + if (n_items > 0) + { + guint j = g_test_rand_int_range (0, n_items); + GListModel *source = g_list_model_get_item (G_LIST_MODEL (store), j); + guint source_size = g_list_model_get_n_items (G_LIST_MODEL (source)); + GStrvBuilder *builder = g_strv_builder_new (); + guint inclusion_size = g_test_rand_int_range (1, 11); + char **inclusion; + + for (j = 0; j < inclusion_size; j++) + g_strv_builder_add (builder, g_test_rand_bit () ? "A" : "B"); + inclusion = g_strv_builder_end (builder); + g_strv_builder_unref (builder); + + j = g_test_rand_int_range (0, source_size + 1); + gtk_string_list_splice (GTK_STRING_LIST (source), j, 0, (const char * const *) inclusion); + g_strfreev (inclusion); + + if (g_test_verbose ()) + g_test_message ("Adding %u items at position %u of a section which had %u items", + inclusion_size, j, source_size); + } + } + break; + default: g_assert_not_reached (); break;