Skip to content

Commit

Permalink
Merge pull request #6302 from smoogipoo/fix-dropdown-remove-on-change
Browse files Browse the repository at this point in the history
Fix crash when dropdown is removed from hierarchy during select
  • Loading branch information
bdach authored May 27, 2024
2 parents efb30d9 + 3b26686 commit ea28ffb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion osu.Framework.Tests/Visual/UserInterface/TestSceneDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ void checkOrder(int index, string item) => AddAssert($"item #{index + 1} is '{it
}

[Test]
[Solo]
public void TestExternalManagement()
{
TestDropdown dropdown = null!;
Expand Down Expand Up @@ -483,6 +482,32 @@ public void TestSetNonExistentItem([Values] bool afterBdl)
AddAssert("text is expected", () => dropdown.SelectedItem.Text.Value.ToString(), () => Is.EqualTo("loaded: non-existent item"));
}

[Test]
public void TestRemoveDropdownOnSelect()
{
TestDropdown testDropdown = null!;
Bindable<TestModel?> bindable = null!;

AddStep("setup dropdown", () =>
{
bindable = new Bindable<TestModel?>();
bindable.ValueChanged += _ => createDropdown();

testDropdown = createDropdown();
testDropdown.Current = bindable;
});

toggleDropdownViaClick(() => testDropdown);

AddStep("click item 2", () =>
{
InputManager.MoveMouseTo(testDropdown.Menu.Children[2]);
InputManager.Click(MouseButton.Left);
});

AddAssert("bindable value is item 2", () => bindable.Value?.Identifier == "test 2");
}

#region Searching

[Test]
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/UserInterface/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ void IDropdown.CommitPreselection()
SelectedItem = (DropdownMenuItem<T>)preselectedItem.Item;
}

void IDropdown.TriggerFocusContention(Drawable triggerSource) => GetContainingFocusManager().TriggerFocusContention(triggerSource);
void IDropdown.TriggerFocusContention(Drawable triggerSource) => GetContainingFocusManager()?.TriggerFocusContention(triggerSource);

bool IDropdown.ChangeFocus(Drawable potentialFocusTarget) => GetContainingFocusManager().ChangeFocus(potentialFocusTarget);
bool IDropdown.ChangeFocus(Drawable potentialFocusTarget) => GetContainingFocusManager()?.ChangeFocus(potentialFocusTarget) ?? false;

#endregion
}
Expand Down

0 comments on commit ea28ffb

Please sign in to comment.