diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs index 6c75530a6e..8ddbd84890 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs @@ -612,6 +612,23 @@ namespace osu.Game.Tests.Visual.UserInterface AddAssert("search text box unfocused", () => !modSelectOverlay.SearchTextBox.HasFocus); } + [Test] + public void TestSearchBoxFocusToggleRespondsToExternalChanges() + { + AddStep("text search does not start active", () => configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, false)); + createScreen(); + + AddUntilStep("search text box not focused", () => !modSelectOverlay.SearchTextBox.HasFocus); + + AddStep("press tab", () => InputManager.Key(Key.Tab)); + AddAssert("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus); + + AddStep("unfocus search text box externally", () => InputManager.ChangeFocus(null)); + + AddStep("press tab", () => InputManager.Key(Key.Tab)); + AddAssert("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus); + } + [Test] public void TestTextSearchDoesNotBlockCustomisationPanelKeyboardInteractions() { diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 3325cfe407..25293e8e20 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -143,8 +143,6 @@ namespace osu.Game.Overlays.Mods protected ShearedToggleButton? CustomisationButton { get; private set; } protected SelectAllModsButton? SelectAllModsButton { get; set; } - private bool textBoxShouldFocus; - private Sample? columnAppearSample; private WorkingBeatmap? beatmap; @@ -542,7 +540,7 @@ namespace osu.Game.Overlays.Mods if (customisationVisible.Value) SearchTextBox.KillFocus(); else - setTextBoxFocus(textBoxShouldFocus); + setTextBoxFocus(textSearchStartsActive.Value); } /// @@ -798,15 +796,13 @@ namespace osu.Game.Overlays.Mods return false; // TODO: should probably eventually support typical platform search shortcuts (`Ctrl-F`, `/`) - setTextBoxFocus(!textBoxShouldFocus); + setTextBoxFocus(!SearchTextBox.HasFocus); return true; } - private void setTextBoxFocus(bool keepFocus) + private void setTextBoxFocus(bool focus) { - textBoxShouldFocus = keepFocus; - - if (textBoxShouldFocus) + if (focus) SearchTextBox.TakeFocus(); else SearchTextBox.KillFocus();