Skip to content

Commit

Permalink
Merge pull request #6485 from 424ever/textbox-drag-crash
Browse files Browse the repository at this point in the history
Fix crash when dragging in a text box while a key is held down
  • Loading branch information
smoogipoo authored Jan 6, 2025
2 parents 0a16e77 + 635ce03 commit e05cb86
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit e05cb86

Please sign in to comment.