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

Fix dragging number boxes overwritten by select-all-on-focus feature

This commit is contained in:
Salman Ahmed 2024-07-24 23:19:04 +03:00
parent 4983e5f33e
commit 6645dac71d
2 changed files with 20 additions and 1 deletions

View File

@ -76,6 +76,24 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left);
});
AddAssert("text selected", () => numberBoxes.First().SelectedText == "987654321");
AddStep("click away", () =>
{
InputManager.MoveMouseTo(Vector2.Zero);
InputManager.Click(MouseButton.Left);
});
Drawable textContainer = null!;
AddStep("move mouse to end of text", () =>
{
textContainer = numberBoxes.First().ChildrenOfType<Container>().ElementAt(1);
InputManager.MoveMouseTo(textContainer.ScreenSpaceDrawQuad.TopRight);
});
AddStep("hold mouse", () => InputManager.PressButton(MouseButton.Left));
AddStep("drag to half", () => InputManager.MoveMouseTo(textContainer.ScreenSpaceDrawQuad.BottomRight - new Vector2(textContainer.ScreenSpaceDrawQuad.Width / 2, 0)));
AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("half text selected", () => numberBoxes.First().SelectedText == "54321");
}
private void clearTextboxes(IEnumerable<OsuTextBox> textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null));

View File

@ -261,7 +261,8 @@ namespace osu.Game.Graphics.UserInterface
base.OnFocus(e);
if (SelectAllOnFocus)
// we may become focused from an ongoing drag operation, we don't want to overwrite selection in that case.
if (SelectAllOnFocus && string.IsNullOrEmpty(SelectedText))
SelectAll();
}