Fix incorrect selection restore code in split case

The fallback to "any of the added sets" needs to be applied after
they've all been added, rather than with every added one. Otherwise, in
flows that expect a particular difficulty to be selected in the end
(such as exiting from editor) would end up switching away from the
edited beatmap.
This commit is contained in:
Bartłomiej Dach 2023-08-28 10:06:26 +02:00
parent 0af6cc1394
commit 80ec18d117
No known key found for this signature in database
1 changed files with 11 additions and 4 deletions

View File

@ -419,6 +419,8 @@ public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
if (beatmapsSplitOut)
{
var newSets = new List<CarouselBeatmapSet>();
foreach (var beatmap in beatmapSet.Beatmaps)
{
var newSet = createCarouselSet(new BeatmapSetInfo(new[] { beatmap })
@ -429,13 +431,18 @@ public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
if (newSet != null)
{
newSets.Add(newSet);
root.AddItem(newSet);
// check if we can/need to maintain our current selection.
if (previouslySelectedID != null)
select((CarouselItem?)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
}
}
// check if we can/need to maintain our current selection.
if (previouslySelectedID != null)
{
var toSelect = newSets.FirstOrDefault(s => s.Beatmaps.Any(b => b.BeatmapInfo.ID == previouslySelectedID))
?? newSets.FirstOrDefault();
select(toSelect);
}
}
else
{