Skip to content

Commit

Permalink
Fix RearrangeableListContainer crashing on range replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Nov 14, 2024
1 parent 9e38585 commit 240399f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions osu.Framework/Graphics/Containers/RearrangeableListContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,16 @@ private void collectionChanged(object sender, NotifyCollectionChangedEventArgs e
currentlyDraggedItem = null;
ListContainer.Clear();
itemMap.Clear();
OnItemsChanged();
break;

case NotifyCollectionChangedAction.Replace:
removeItems(e.OldItems);
addItems(e.NewItems);
break;

case NotifyCollectionChangedAction.Move:
sortItems();
OnItemsChanged();
break;
}

sortItems();
OnItemsChanged();
}

private void removeItems(IList items)
Expand All @@ -132,9 +129,6 @@ private void removeItems(IList items)

itemMap.Remove(item);
}

sortItems();
OnItemsChanged();
}

private void addItems(IList items)
Expand Down Expand Up @@ -163,7 +157,14 @@ private void addItems(IList items)
if (!IsLoaded)
addToHierarchy(drawablesToAdd);
else
LoadComponentsAsync(drawablesToAdd, addToHierarchy);
{
LoadComponentsAsync(drawablesToAdd, d =>
{
addToHierarchy(d);
sortItems();
OnItemsChanged();
});
}

void addToHierarchy(IEnumerable<Drawable> drawables)
{
Expand All @@ -173,9 +174,6 @@ void addToHierarchy(IEnumerable<Drawable> drawables)
if (itemMap.TryGetValue(d.Model, out var modelDrawable) && modelDrawable == d)
ListContainer.Add(d);
}

sortItems();
OnItemsChanged();
}
}

Expand Down

0 comments on commit 240399f

Please sign in to comment.