1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00

Merge pull request #28805 from frenzibyte/select-all-on-focus

Select all text when focusing sample bank/volume textboxes in editor (and number boxes in general)
This commit is contained in:
Dean Herbert 2024-07-11 17:33:30 +09:00 committed by GitHub
commit c139478aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 1 deletions

View File

@ -11,6 +11,7 @@ using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
@ -61,6 +62,22 @@ namespace osu.Game.Tests.Visual.UserInterface
clearTextboxes(numberBoxes);
}
[Test]
public void TestSelectAllOnFocus()
{
AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red));
AddStep("enter numbers", () => numberBoxes.ForEach(numberBox => numberBox.Text = "987654321"));
AddAssert("nothing selected", () => string.IsNullOrEmpty(numberBoxes.First().SelectedText));
AddStep("click on a number box", () =>
{
InputManager.MoveMouseTo(numberBoxes.First());
InputManager.Click(MouseButton.Left);
});
AddAssert("text selected", () => numberBoxes.First().SelectedText == "987654321");
}
private void clearTextboxes(IEnumerable<OsuTextBox> textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null));
private void expectedValue(IEnumerable<OsuTextBox> textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textBox => textBox.Text == value));
}

View File

@ -7,6 +7,11 @@ namespace osu.Game.Graphics.UserInterface
{
protected override bool AllowIme => false;
public OsuNumberBox()
{
SelectAllOnFocus = true;
}
protected override bool CanAddCharacter(char character) => char.IsAsciiDigit(character);
}
}

View File

@ -63,6 +63,11 @@ namespace osu.Game.Graphics.UserInterface
private Dictionary<FeedbackSampleType, Sample?[]> sampleMap = new Dictionary<FeedbackSampleType, Sample?[]>();
/// <summary>
/// Whether all text should be selected when the <see cref="OsuTextBox"/> gains focus.
/// </summary>
public bool SelectAllOnFocus { get; set; }
public OsuTextBox()
{
Height = 40;
@ -255,6 +260,9 @@ namespace osu.Game.Graphics.UserInterface
BorderThickness = 3;
base.OnFocus(e);
if (SelectAllOnFocus)
SelectAll();
}
protected override void OnFocusLost(FocusLostEvent e)

View File

@ -28,6 +28,12 @@ namespace osu.Game.Graphics.UserInterfaceV2
set => Component.ReadOnly = value;
}
public bool SelectAllOnFocus
{
get => Component.SelectAllOnFocus;
set => Component.SelectAllOnFocus = value;
}
public LocalisableString PlaceholderText
{
set => Component.PlaceholderText = value;

View File

@ -148,10 +148,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
bank = new LabelledTextBox
{
Label = "Bank Name",
SelectAllOnFocus = true,
},
additionBank = new LabelledTextBox
{
Label = "Addition Bank",
SelectAllOnFocus = true,
},
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new BindableInt(100)
{

View File

@ -51,7 +51,8 @@ namespace osu.Game.Screens.Edit.Timing
{
textBox = new LabelledTextBox
{
Label = "Time"
Label = "Time",
SelectAllOnFocus = true,
},
button = new RoundedButton
{

View File

@ -75,6 +75,7 @@ namespace osu.Game.Screens.Edit.Timing
textBox = new LabelledTextBox
{
Label = labelText,
SelectAllOnFocus = true,
},
slider = new SettingsSlider<T>
{

View File

@ -79,6 +79,7 @@ namespace osu.Game.Screens.Edit.Timing
public BPMTextBox()
{
Label = "BPM";
SelectAllOnFocus = true;
OnCommit += (_, isNew) =>
{