mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 11:12:59 +08:00
Select all text when focusing a number box
This commit is contained in:
parent
d879527329
commit
94f51c92e0
@ -11,6 +11,7 @@ using osu.Framework.Testing;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -61,6 +62,22 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
clearTextboxes(numberBoxes);
|
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 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));
|
private void expectedValue(IEnumerable<OsuTextBox> textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textBox => textBox.Text == value));
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,11 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
protected override bool AllowIme => false;
|
protected override bool AllowIme => false;
|
||||||
|
|
||||||
|
public OsuNumberBox()
|
||||||
|
{
|
||||||
|
SelectAllOnFocus = true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool CanAddCharacter(char character) => char.IsAsciiDigit(character);
|
protected override bool CanAddCharacter(char character) => char.IsAsciiDigit(character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,11 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private Dictionary<FeedbackSampleType, Sample?[]> sampleMap = new Dictionary<FeedbackSampleType, Sample?[]>();
|
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()
|
public OsuTextBox()
|
||||||
{
|
{
|
||||||
Height = 40;
|
Height = 40;
|
||||||
@ -255,6 +260,9 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
BorderThickness = 3;
|
BorderThickness = 3;
|
||||||
|
|
||||||
base.OnFocus(e);
|
base.OnFocus(e);
|
||||||
|
|
||||||
|
if (SelectAllOnFocus)
|
||||||
|
SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFocusLost(FocusLostEvent e)
|
protected override void OnFocusLost(FocusLostEvent e)
|
||||||
|
@ -28,6 +28,12 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
set => Component.ReadOnly = value;
|
set => Component.ReadOnly = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SelectAllOnFocus
|
||||||
|
{
|
||||||
|
get => Component.SelectAllOnFocus;
|
||||||
|
set => Component.SelectAllOnFocus = value;
|
||||||
|
}
|
||||||
|
|
||||||
public LocalisableString PlaceholderText
|
public LocalisableString PlaceholderText
|
||||||
{
|
{
|
||||||
set => Component.PlaceholderText = value;
|
set => Component.PlaceholderText = value;
|
||||||
|
Loading…
Reference in New Issue
Block a user