Skip to content

Commit

Permalink
Scroll to new collection in list when adding a new collection
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Nov 18, 2024
1 parent 0aead2b commit 8e54ad7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions osu.Game/Collections/DrawableCollectionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ protected override void LoadComplete()
realmSubscription = realm.RegisterForNotifications(r => r.All<BeatmapCollection>().OrderBy(c => c.Name), collectionsChanged);
}

/// <summary>
/// When non-null, signifies that a new collection was created and should be presented to the user.
/// </summary>
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<BeatmapCollection> collections, ChangeSet? changes)
{
if (changes == null)
Expand All @@ -60,7 +80,11 @@ private void collectionsChanged(IRealmCollection<BeatmapCollection> 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];

Expand Down

0 comments on commit 8e54ad7

Please sign in to comment.