From d877536dc0ec8d1f8f1889be73740a58ef29f869 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 29 Oct 2023 01:03:38 +0300 Subject: [PATCH 1/6] Select all text content in `SearchTextBox` on focus --- osu.Game/Graphics/UserInterface/SearchTextBox.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Graphics/UserInterface/SearchTextBox.cs b/osu.Game/Graphics/UserInterface/SearchTextBox.cs index a2e0ab6482..b554c2bbd8 100644 --- a/osu.Game/Graphics/UserInterface/SearchTextBox.cs +++ b/osu.Game/Graphics/UserInterface/SearchTextBox.cs @@ -18,6 +18,12 @@ namespace osu.Game.Graphics.UserInterface PlaceholderText = HomeStrings.SearchPlaceholder; } + protected override void OnFocus(FocusEvent e) + { + base.OnFocus(e); + SelectAll(); + } + public override bool OnPressed(KeyBindingPressEvent e) { switch (e.Action) From 31c6973bb646272b3ddcb2b3405d1802c8bf770c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 29 Oct 2023 01:03:45 +0300 Subject: [PATCH 2/6] Add test coverage --- .../UserInterface/TestSceneSearchTextBox.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs new file mode 100644 index 0000000000..153525d24a --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs @@ -0,0 +1,38 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; +using osuTK; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public partial class TestSceneSearchTextBox : OsuTestScene + { + private SearchTextBox textBox = null!; + + [SetUp] + public void SetUp() => Schedule(() => + { + Child = textBox = new SearchTextBox + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = 400, + Scale = new Vector2(2f), + HoldFocus = true, + }; + }); + + [Test] + public void TestSelectionOnFocus() + { + AddStep("set text", () => textBox.Text = "some text"); + AddAssert("no text selected", () => textBox.SelectedText == string.Empty); + AddStep("hide text box", () => textBox.Hide()); + AddStep("show text box", () => textBox.Show()); + AddAssert("search text selected", () => textBox.SelectedText == textBox.Text); + } + } +} From c7bc8e686543e4fe6e823d06b5d79be144d8ad6e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 30 Oct 2023 06:41:01 +0300 Subject: [PATCH 3/6] Move behaviour to settings search text box only --- .../Visual/Settings/TestSceneSettingsPanel.cs | 11 +++++++++++ .../Graphics/UserInterface/SearchTextBox.cs | 6 ------ osu.Game/Overlays/SettingsPanel.cs | 2 +- osu.Game/Overlays/SettingsSearchTextBox.cs | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Overlays/SettingsSearchTextBox.cs diff --git a/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs b/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs index 24c2eee783..69e489b247 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs @@ -140,6 +140,17 @@ namespace osu.Game.Tests.Visual.Settings AddUntilStep("top-level textbox focused", () => settings.SectionsContainer.ChildrenOfType().FirstOrDefault()?.HasFocus == true); } + [Test] + public void TestSearchTextBoxSelectedOnShow() + { + SearchTextBox searchTextBox = null!; + + AddStep("set text", () => (searchTextBox = settings.SectionsContainer.ChildrenOfType().First()).Current.Value = "some text"); + AddAssert("no text selected", () => searchTextBox.SelectedText == string.Empty); + AddRepeatStep("toggle visibility", () => settings.ToggleVisibility(), 2); + AddAssert("search text selected", () => searchTextBox.SelectedText == searchTextBox.Current.Value); + } + [BackgroundDependencyLoader] private void load() { diff --git a/osu.Game/Graphics/UserInterface/SearchTextBox.cs b/osu.Game/Graphics/UserInterface/SearchTextBox.cs index b554c2bbd8..a2e0ab6482 100644 --- a/osu.Game/Graphics/UserInterface/SearchTextBox.cs +++ b/osu.Game/Graphics/UserInterface/SearchTextBox.cs @@ -18,12 +18,6 @@ namespace osu.Game.Graphics.UserInterface PlaceholderText = HomeStrings.SearchPlaceholder; } - protected override void OnFocus(FocusEvent e) - { - base.OnFocus(e); - SelectAll(); - } - public override bool OnPressed(KeyBindingPressEvent e) { switch (e.Action) diff --git a/osu.Game/Overlays/SettingsPanel.cs b/osu.Game/Overlays/SettingsPanel.cs index 2517a58491..3bac6c400f 100644 --- a/osu.Game/Overlays/SettingsPanel.cs +++ b/osu.Game/Overlays/SettingsPanel.cs @@ -135,7 +135,7 @@ namespace osu.Game.Overlays }, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Child = searchTextBox = new SeekLimitedSearchTextBox + Child = searchTextBox = new SettingsSearchTextBox { RelativeSizeAxes = Axes.X, Origin = Anchor.TopCentre, diff --git a/osu.Game/Overlays/SettingsSearchTextBox.cs b/osu.Game/Overlays/SettingsSearchTextBox.cs new file mode 100644 index 0000000000..bafa6e26eb --- /dev/null +++ b/osu.Game/Overlays/SettingsSearchTextBox.cs @@ -0,0 +1,18 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable +using osu.Framework.Input.Events; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Overlays +{ + public partial class SettingsSearchTextBox : SeekLimitedSearchTextBox + { + protected override void OnFocus(FocusEvent e) + { + base.OnFocus(e); + SelectAll(); + } + } +} From 39abb8e4085d17bc8ff64a80f19e268a3d4a5b7f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 30 Oct 2023 11:54:19 +0300 Subject: [PATCH 4/6] Only run "select all on focus" behaviour on desktop platforms --- osu.Game/Overlays/SettingsSearchTextBox.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SettingsSearchTextBox.cs b/osu.Game/Overlays/SettingsSearchTextBox.cs index bafa6e26eb..84cff1b508 100644 --- a/osu.Game/Overlays/SettingsSearchTextBox.cs +++ b/osu.Game/Overlays/SettingsSearchTextBox.cs @@ -12,7 +12,11 @@ namespace osu.Game.Overlays protected override void OnFocus(FocusEvent e) { base.OnFocus(e); - SelectAll(); + + // on mobile platforms, focus is not held by the search text box, and the select all feature + // will not make sense on it, and might annoy the user when they try to focus manually. + if (HoldFocus) + SelectAll(); } } } From 88e10dd051d33ca0e63a7cd5f82dac3d9b4e039c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 30 Oct 2023 20:03:44 +0100 Subject: [PATCH 5/6] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 0575817460..2870696c03 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -10,7 +10,7 @@ true - + diff --git a/osu.iOS.props b/osu.iOS.props index 9b06b4a6a7..f1159f58b9 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -23,6 +23,6 @@ iossimulator-x64 - + From 06508d08fe1f289404bb20756f43403c209e0d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 30 Oct 2023 20:22:41 +0100 Subject: [PATCH 6/6] Delete outdated test --- .../UserInterface/TestSceneSearchTextBox.cs | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs deleted file mode 100644 index 153525d24a..0000000000 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneSearchTextBox.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using NUnit.Framework; -using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; -using osuTK; - -namespace osu.Game.Tests.Visual.UserInterface -{ - public partial class TestSceneSearchTextBox : OsuTestScene - { - private SearchTextBox textBox = null!; - - [SetUp] - public void SetUp() => Schedule(() => - { - Child = textBox = new SearchTextBox - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Width = 400, - Scale = new Vector2(2f), - HoldFocus = true, - }; - }); - - [Test] - public void TestSelectionOnFocus() - { - AddStep("set text", () => textBox.Text = "some text"); - AddAssert("no text selected", () => textBox.SelectedText == string.Empty); - AddStep("hide text box", () => textBox.Hide()); - AddStep("show text box", () => textBox.Show()); - AddAssert("search text selected", () => textBox.SelectedText == textBox.Text); - } - } -}