1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Add hotkey for switching search bar focus

This commit is contained in:
Cootz 2023-06-05 15:54:19 +03:00
parent 3ebc801484
commit 71e6f80c40
2 changed files with 32 additions and 4 deletions

View File

@ -546,16 +546,16 @@ namespace osu.Game.Tests.Visual.UserInterface
}
[Test]
public void TestSearchFocusChange()
public void TestSearchFocusChangeViaClick()
{
createScreen();
AddStep("click on search", navigateAndClick<ShearedSearchTextBox>);
AddAssert("focused", () => modSelectOverlay.SearchTextBox.HasFocus);
AddStep("click on mod column", navigateAndClick<ModColumn>);
AddAssert("lost focus", () => !modSelectOverlay.SearchTextBox.HasFocus);
AddStep("click on search", navigateAndClick<ShearedSearchTextBox>);
AddAssert("focused", () => modSelectOverlay.SearchTextBox.HasFocus);
void navigateAndClick<T>() where T : Drawable
{
InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType<T>().FirstOrDefault());
@ -563,6 +563,20 @@ namespace osu.Game.Tests.Visual.UserInterface
}
}
[Test]
public void TestSearchFocusChangeViaKey()
{
createScreen();
const Key focus_switch_key = Key.Tab;
AddStep("press tab", () => InputManager.Key(focus_switch_key));
AddAssert("lost focus", () => !modSelectOverlay.SearchTextBox.HasFocus);
AddStep("press tab", () => InputManager.Key(focus_switch_key));
AddAssert("focused", () => modSelectOverlay.SearchTextBox.HasFocus);
}
[Test]
public void TestDeselectAllViaKey()
{

View File

@ -27,6 +27,7 @@ using osu.Game.Localisation;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using osuTK;
using osuTK.Input;
namespace osu.Game.Overlays.Mods
{
@ -684,6 +685,19 @@ namespace osu.Game.Overlays.Mods
{
}
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Repeat || e.Key != Key.Tab)
return false;
if (SearchTextBox.HasFocus)
SearchTextBox.KillFocus();
else
SearchTextBox.TakeFocus();
return true;
}
#endregion
#region Sample playback control