From 2ab06a04aa8a309966dfe251132092197b19a0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Brandst=C3=B6tter?= Date: Sat, 4 Jan 2025 19:56:59 +0100 Subject: [PATCH 1/2] Prevent crashing when dragging in a text box while a key is held down --- .../Visual/UserInterface/TestSceneTextBox.cs | 34 +++++++++++++++++++ .../Graphics/UserInterface/TextBox.cs | 1 + 2 files changed, 35 insertions(+) diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs index 1242f984f3..6c3a50179a 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs @@ -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() { diff --git a/osu.Framework/Graphics/UserInterface/TextBox.cs b/osu.Framework/Graphics/UserInterface/TextBox.cs index e825299cd2..75e780bb1d 100644 --- a/osu.Framework/Graphics/UserInterface/TextBox.cs +++ b/osu.Framework/Graphics/UserInterface/TextBox.cs @@ -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(); From 635ce0301fed51879fb96710ef12e9ae7c0c7e91 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 6 Jan 2025 11:35:13 +0900 Subject: [PATCH 2/2] Resolve inspection issue --- osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs index 6c3a50179a..5fcafb4290 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs @@ -800,7 +800,7 @@ public void TestSetTextSelection() AddAssert("nothing selected", () => textBox.SelectedText == string.Empty); } - [Test()] + [Test] public void TestTextChangedDuringDoubleClickDrag() { InsertableTextBox textBox = null;