1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-02 03:42:57 +08:00

Refactor a bit

This commit is contained in:
Dan Balasescu 2024-10-18 18:40:25 +09:00
parent 9a0356919c
commit 083644b713
No known key found for this signature in database

View File

@ -590,20 +590,18 @@ namespace osu.Game.Overlays.Mods
return true; return true;
} }
//matchingMod ensures that if an exact mod acronym is typed, it will be selected when Select is pressed (as opposed to being prioritized in arbitrary column order) IEnumerable<ModState> visibleMods = columnFlow.Columns.OfType<ModColumn>().Where(c => c.IsPresent).SelectMany(c => c.AvailableMods.Where(m => m.Visible));
ModState? firstMod = columnFlow.Columns.OfType<ModColumn>().FirstOrDefault(m => m.IsPresent)?.AvailableMods.FirstOrDefault(x => x.Visible);
ModState? matchingMod = columnFlow.Columns.OfType<ModColumn>().SelectMany(m => m.AvailableMods).FirstOrDefault(x => x.Mod.Acronym.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase) | x.Mod.Name.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase)); // Search for an exact acronym or name match, or otherwise default to the first visible mod.
ModState? matchingMod =
visibleMods.FirstOrDefault(m => m.Mod.Acronym.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase) || m.Mod.Name.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase))
?? visibleMods.FirstOrDefault();
if (matchingMod is not null) if (matchingMod is not null)
{ {
matchingMod.Active.Value = !matchingMod.Active.Value; matchingMod.Active.Value = !matchingMod.Active.Value;
SearchTextBox.SelectAll(); SearchTextBox.SelectAll();
} }
else if (firstMod is not null)
{
firstMod.Active.Value = !firstMod.Active.Value;
SearchTextBox.SelectAll();
}
return true; return true;
} }