From 46b2d5374eceedfde35bc172af0137495189f4fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 20 Jan 2026 19:36:21 +0900 Subject: [PATCH] Refactor `HandleFilterCompleted` to (hopefully) be easier to parse This is not required to fix the issue, but it is required for my brain to follow the method to some degress. --- osu.Game/Screens/SelectV2/BeatmapCarousel.cs | 53 +++++++++----------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/osu.Game/Screens/SelectV2/BeatmapCarousel.cs b/osu.Game/Screens/SelectV2/BeatmapCarousel.cs index e0f46af409..72d59c62f7 100644 --- a/osu.Game/Screens/SelectV2/BeatmapCarousel.cs +++ b/osu.Game/Screens/SelectV2/BeatmapCarousel.cs @@ -482,40 +482,37 @@ namespace osu.Game.Screens.SelectV2 attemptSelectSingleFilteredResult(); - // Store selected group before handling selection (it may implicitly change the expanded group). - var groupForReselection = ExpandedGroup; - - var currentGroupedBeatmap = CurrentSelection as GroupedBeatmap; - - // The filter might have changed the set of available groups, which means that the current selection may point to a stale group. - // Check whether that is the case. - bool groupingRemainsOff = currentGroupedBeatmap?.Group == null && grouping.GroupItems.Count == 0; - bool groupStillValid = currentGroupedBeatmap?.Group != null && grouping.ItemMap.ContainsKey(currentGroupedBeatmap); - - if (groupingRemainsOff || groupStillValid) + if (CurrentSelection is GroupedBeatmap selection) { - // Update the visual state of the selected item if it should still be expanded post filter. - if (currentGroupedBeatmap != null && currentGroupedBeatmap.Group == groupForReselection) - setExpandedSet(new GroupedBeatmapSet(currentGroupedBeatmap.Group, currentGroupedBeatmap.Beatmap.BeatmapSet!)); - } - else if (currentGroupedBeatmap != null) - { - // If the group no longer exists (or the item no longer exists in the previous group), grab an arbitrary other instance of the beatmap under the first group encountered. - var newSelection = GetCarouselItems()?.Select(i => i.Model).OfType().FirstOrDefault(gb => gb.Beatmap.Equals(currentGroupedBeatmap.Beatmap)); + // The filter might have changed the set of available groups, which means that the current selection may point to a stale group. + // Check whether that is the case. + bool groupingRemainsOff = selection.Group == null && grouping.GroupItems.Count == 0; + bool groupStillValid = selection.Group != null && grouping.ItemMap.ContainsKey(selection); - // Only change the selection if we actually got a positive hit. - // This is necessary so that selection isn't lost if the panel reappears later due to e.g. unapplying some filter criteria that made it disappear in the first place. - if (newSelection != null) + if (groupingRemainsOff || groupStillValid) { - CurrentSelection = newSelection; - groupForReselection = newSelection.Group; + if (selection.Group == ExpandedGroup) + { + // Update the visual state of the selected item if it should still be expanded post filter. + HandleItemSelected(CurrentSelection); + } + } + else + { + // If the group no longer exists (or the item no longer exists in the previous group), grab an arbitrary other instance of the beatmap under the first group encountered. + var newSelection = GetCarouselItems()?.Select(i => i.Model).OfType().FirstOrDefault(gb => gb.Beatmap.Equals(selection.Beatmap)); + + // Only change the selection if we actually got a positive hit. + // This is necessary so that selection isn't lost if the panel reappears later due to e.g. unapplying some filter criteria that made it disappear in the first place. + if (newSelection != null) + { + CurrentSelection = newSelection; + // have to run this here as the above operation may noop on model equality. + HandleItemSelected(CurrentSelection); + } } } - // If a group was selected that is not the one containing the selection, attempt to reselect it. - if (groupForReselection != null && grouping.GroupItems.TryGetValue(groupForReselection, out _)) - setExpandedGroup(groupForReselection); - foreach (var item in Scroll.Panels.OfType().Where(p => p.Item != null)) updateVisibleBeatmaps((GroupedBeatmapSet)item.Item!.Model, item); }