1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Fix test failures due to selection/item collection desyncs

This commit is contained in:
Bartłomiej Dach 2022-05-04 13:51:47 +02:00
parent 0405c1c34a
commit e6fdef2d7a
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -178,14 +177,19 @@ namespace osu.Game.Screens.OnlinePlay
{
base.LoadComplete();
SelectedItem.BindValueChanged(_ => scrollToSelection(), true);
// schedules added as the properties may change value while the drawable items haven't been created yet.
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(scrollToSelection));
Items.BindCollectionChanged((_, __) => Scheduler.AddOnce(scrollToSelection), true);
}
private void scrollToSelection()
{
if (SelectedItem.Value == null) return;
// SelectedItem and ItemMap/drawable items are managed separately,
// so if the item can't be unmapped to a drawable, don't try to scroll to it.
// best effort is made to not drop any updates, by subscribing to both sources.
if (SelectedItem.Value == null || !ItemMap.TryGetValue(SelectedItem.Value, out var drawableItem))
return;
Debug.Assert(ItemMap.TryGetValue(SelectedItem.Value, out var drawableItem));
ScrollContainer.ScrollIntoView(drawableItem);
}