Skip to content

Commit

Permalink
Remove necessity of clearing item selection on Clear to maintain be…
Browse files Browse the repository at this point in the history
…haviour
  • Loading branch information
frenzibyte committed Dec 5, 2023
1 parent 9d3275e commit 4d359a9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions osu.Framework/Graphics/UserInterface/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public IBindableList<T> ItemSource
private void setItems(IEnumerable<T> value)
{
clearItems();

if (value == null)
return;

Expand Down Expand Up @@ -347,8 +348,7 @@ private void ensureItemSelectionIsValid()
return;
}

if (SelectedItem == null || !EqualityComparer<T>.Default.Equals(Current.Value, selectedItem.Value))
updateItemSelection(Current.Value);
updateItemSelection(Current.Value);
}

private void updateItemSelection(T value)
Expand Down Expand Up @@ -382,7 +382,6 @@ private void clearItems()
{
itemMap.Clear();
Menu.Clear();
selectedItem = null;
}

/// <summary>
Expand Down Expand Up @@ -450,8 +449,9 @@ public void SelectItem(DropdownMenuItem<T> item)
{
Children.OfType<DrawableDropdownMenuItem>().ForEach(c =>
{
bool wasSelected = c.IsSelected;
c.IsSelected = compareItemEquality(item, c.Item);
if (c.IsSelected)
if (c.IsSelected && !wasSelected)
ContentContainer.ScrollIntoView(c);
});
}
Expand Down Expand Up @@ -483,8 +483,9 @@ protected void PreselectItem(MenuItem item)
{
Children.OfType<DrawableDropdownMenuItem>().ForEach(c =>
{
bool wasPreSelected = c.IsPreSelected;
c.IsPreSelected = compareItemEquality(item, c.Item);
if (c.IsPreSelected)
if (c.IsPreSelected && !wasPreSelected)
ContentContainer.ScrollIntoView(c);
});
}
Expand Down

0 comments on commit 4d359a9

Please sign in to comment.