Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when dragging in a text box while a key is held down #6485

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,40 @@ public void TestSetTextSelection()
AddAssert("nothing selected", () => textBox.SelectedText == string.Empty);
}

[Test]
public void TestTextChangedDuringDoubleClickDrag()
{
InsertableTextBox textBox = null;

AddStep("add textbox", () =>
{
textBoxes.Add(textBox = new InsertableTextBox
{
Size = new Vector2(300, 40),
Text = "initial text",
});
});

AddStep("click on textbox", () =>
{
InputManager.MoveMouseTo(textBox);
InputManager.Click(MouseButton.Left);
});

AddStep("set text", () => textBox.Text = "aaaaaaaaaaaaaaaaaaaa");

AddStep("select word", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.PressButton(MouseButton.Left);
});

AddStep("insert text", () => textBox.InsertString("a"));
AddAssert("text overwritten", () => textBox.Text == "a");
AddStep("start drag", () => InputManager.MoveMouseTo(textBox, new Vector2(-50, 0)));
AddStep("end drag", () => InputManager.ReleaseButton(MouseButton.Left));
}

[Test]
public void TestSelectAll()
{
Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Graphics/UserInterface/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ private string removeCharacters(int number = 1)
TextFlow.ChangeChildDepth(TextFlow[i], getDepthForCharacterIndex(i));

selectionStart = selectionEnd = removeStart;
doubleClickWord = null;

endTextChange(beganChange);
cursorAndLayout.Invalidate();
Expand Down
Loading