Skip to content

Commit

Permalink
Merge pull request #25857 from peppy/fix-mod-settings-keyboard-adjust
Browse files Browse the repository at this point in the history
Fix mod search textbox having focus while settings are visible
  • Loading branch information
bdach authored Dec 19, 2023
2 parents b869973 + d793d1c commit 64b0534
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
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 @@ void navigateAndClick<T>() where T : Drawable
[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

0 comments on commit 64b0534

Please sign in to comment.