Skip to content

Commit

Permalink
Adjust group traversal logic to handle cases where keyboard selection…
Browse files Browse the repository at this point in the history
… redirects
  • Loading branch information
peppy committed Feb 3, 2025
1 parent b5c4e3b commit e454fa5
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions osu.Game/Screens/SelectV2/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,26 +377,31 @@ private void traverseGroupSelection(int direction)
if (currentSelection.CarouselItem != currentKeyboardSelection.CarouselItem)
{
TryActivateSelection();
return;

// There's a chance this couldn't resolve, at which point continue with standard traversal.
if (currentSelection.CarouselItem == currentKeyboardSelection.CarouselItem)
return;
}

int originalIndex;
int newIndex;

if (currentKeyboardSelection.Index != null)
originalIndex = currentKeyboardSelection.Index.Value;
else if (direction > 0)
originalIndex = carouselItems.Count - 1;
if (currentSelection.Index == null)
{
// If there's no current selection, start from either end of the full list.
newIndex = originalIndex = direction > 0 ? carouselItems.Count - 1 : 0;
}
else
originalIndex = 0;

int newIndex = originalIndex;

// As a second special case, if we're group selecting backwards and the current selection isn't a group,
// make sure to go back to the group header this item belongs to, so that the block below doesn't find it and stop too early.
if (direction < 0)
{
while (!CheckValidForGroupSelection(carouselItems[newIndex]))
newIndex--;
newIndex = originalIndex = currentSelection.Index.Value;

// As a second special case, if we're group selecting backwards and the current selection isn't a group,
// make sure to go back to the group header this item belongs to, so that the block below doesn't find it and stop too early.
if (direction < 0)
{
while (!CheckValidForGroupSelection(carouselItems[newIndex]))
newIndex--;
}
}

// Iterate over every item back to the current selection, finding the first valid item.
Expand Down

0 comments on commit e454fa5

Please sign in to comment.