Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mod search textbox having focus while settings are visible #25857

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public void TestSearchFocusChangeViaClick()
[Test]
public void TestTextSearchActiveByDefault()
{
configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, true);
AddStep("text search starts active", () => configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, true));
createScreen();

AddUntilStep("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus);
Expand All @@ -587,7 +587,7 @@ public void TestTextSearchActiveByDefault()
[Test]
public void TestTextSearchNotActiveByDefault()
{
configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, false);
AddStep("text search does not start active", () => configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, false));
createScreen();

AddUntilStep("search text box not focused", () => !modSelectOverlay.SearchTextBox.HasFocus);
Expand All @@ -599,6 +599,31 @@ public void TestTextSearchNotActiveByDefault()
AddAssert("search text box unfocused", () => !modSelectOverlay.SearchTextBox.HasFocus);
}

[Test]
public void TestTextSearchDoesNotBlockCustomisationPanelKeyboardInteractions()
{
AddStep("text search starts active", () => configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, true));
createScreen();

AddUntilStep("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus);

AddStep("select DT", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime() });
AddAssert("DT selected", () => modSelectOverlay.ChildrenOfType<ModPanel>().Count(panel => panel.Active.Value), () => Is.EqualTo(1));

AddStep("open customisation area", () => modSelectOverlay.CustomisationButton!.TriggerClick());
assertCustomisationToggleState(false, true);
AddStep("hover over mod settings slider", () =>
{
var slider = modSelectOverlay.ChildrenOfType<ModSettingsArea>().Single().ChildrenOfType<OsuSliderBar<double>>().First();
InputManager.MoveMouseTo(slider);
});
AddStep("press right arrow", () => InputManager.PressKey(Key.Right));
AddAssert("DT speed changed", () => !SelectedMods.Value.OfType<OsuModDoubleTime>().Single().SpeedChange.IsDefault);

AddStep("close customisation area", () => InputManager.PressKey(Key.Escape));
AddUntilStep("search text box reacquired focus", () => modSelectOverlay.SearchTextBox.HasFocus);
}

[Test]
public void TestDeselectAllViaKey()
{
Expand Down
26 changes: 19 additions & 7 deletions osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ protected virtual IEnumerable<ShearedButton> CreateFooterButtons()
protected ShearedToggleButton? CustomisationButton { get; private set; }
protected SelectAllModsButton? SelectAllModsButton { get; set; }

private bool textBoxShouldFocus;

private Sample? columnAppearSample;

private WorkingBeatmap? beatmap;
Expand Down Expand Up @@ -508,6 +510,11 @@ private void updateCustomisationVisualState()

modSettingsArea.ResizeHeightTo(modAreaHeight, transition_duration, Easing.InOutCubic);
TopLevelContent.MoveToY(-modAreaHeight, transition_duration, Easing.InOutCubic);

if (customisationVisible.Value)
SearchTextBox.KillFocus();
else
setTextBoxFocus(textBoxShouldFocus);
}

/// <summary>
Expand Down Expand Up @@ -621,8 +628,7 @@ protected override void PopIn()
nonFilteredColumnCount += 1;
}

if (textSearchStartsActive.Value)
SearchTextBox.TakeFocus();
setTextBoxFocus(textSearchStartsActive.Value);
}

protected override void PopOut()
Expand Down Expand Up @@ -761,14 +767,20 @@ protected override bool OnKeyDown(KeyDownEvent e)
return false;

// TODO: should probably eventually support typical platform search shortcuts (`Ctrl-F`, `/`)
if (SearchTextBox.HasFocus)
SearchTextBox.KillFocus();
else
SearchTextBox.TakeFocus();

setTextBoxFocus(!textBoxShouldFocus);
return true;
}

private void setTextBoxFocus(bool keepFocus)
{
textBoxShouldFocus = keepFocus;

if (textBoxShouldFocus)
SearchTextBox.TakeFocus();
else
SearchTextBox.KillFocus();
}

#endregion

#region Sample playback control
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Overlays/Mods/ModSettingsArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public partial class ModSettingsArea : CompositeDrawable
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;

public override bool AcceptsFocus => true;

public ModSettingsArea()
{
RelativeSizeAxes = Axes.X;
Expand Down