mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 06:52:56 +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:
commit
c139478aa2
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -51,7 +51,8 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
{
|
||||
textBox = new LabelledTextBox
|
||||
{
|
||||
Label = "Time"
|
||||
Label = "Time",
|
||||
SelectAllOnFocus = true,
|
||||
},
|
||||
button = new RoundedButton
|
||||
{
|
||||
|
@ -75,6 +75,7 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
textBox = new LabelledTextBox
|
||||
{
|
||||
Label = labelText,
|
||||
SelectAllOnFocus = true,
|
||||
},
|
||||
slider = new SettingsSlider<T>
|
||||
{
|
||||
|
@ -79,6 +79,7 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
public BPMTextBox()
|
||||
{
|
||||
Label = "BPM";
|
||||
SelectAllOnFocus = true;
|
||||
|
||||
OnCommit += (_, isNew) =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user