From a570863854ba794c4d9c72e84656568ce9c37d1f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 18 Nov 2024 15:12:28 +0900 Subject: [PATCH] Scroll to new collection in list when adding a new collection --- .../Collections/DrawableCollectionList.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index 441b7fabed70..5096dce55c59 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -46,6 +46,26 @@ protected override void LoadComplete() realmSubscription = realm.RegisterForNotifications(r => r.All().OrderBy(c => c.Name), collectionsChanged); } + /// + /// When non-null, signifies that a new collection was created and should be presented to the user. + /// + private Guid? lastCreated; + + protected override void OnItemsChanged() + { + base.OnItemsChanged(); + + if (lastCreated != null) + { + var createdItem = flow.Children.SingleOrDefault(item => item.Model.Value.ID == lastCreated); + + if (createdItem != null) + scroll.ScrollTo(createdItem); + + lastCreated = null; + } + } + private void collectionsChanged(IRealmCollection collections, ChangeSet? changes) { if (changes == null) @@ -60,7 +80,11 @@ private void collectionsChanged(IRealmCollection collections, foreach (int i in changes.InsertedIndices) Items.Insert(i, collections[i].ToLive(realm)); + if (changes.InsertedIndices.Length == 1) + lastCreated = collections[changes.InsertedIndices[0]].ID; + foreach (int i in changes.NewModifiedIndices) + { var updatedItem = collections[i];