Skip to content
44 changes: 44 additions & 0 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,50 @@ public void TestTextChangedDuringDoubleClickDrag()
AddStep("end drag", () => InputManager.ReleaseButton(MouseButton.Left));
}

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

AddStep("add textbox", () =>
{
textBoxes.Add(textBox = new InsertableTextBox
{
Size = new Vector2(300, 40),
Text = "multiple words so a double click cant select it all",
});
});

AddStep("move to textbox", () => InputManager.MoveMouseTo(textBox));

AddStep("triple click", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("all text selected", () => textBox.SelectedText, () => Is.EqualTo(textBox.Text));

AddStep("double click", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddWaitStep("wait to fail triple click", 2);
AddStep("third click", () => InputManager.Click(MouseButton.Left));
AddAssert("no text selected", () => textBox.SelectedText, () => Is.EqualTo(string.Empty));

AddStep("triple click drag", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
InputManager.PressButton(MouseButton.Left);
});
AddStep("start drag", () => InputManager.MoveMouseTo(textBox.ScreenSpaceDrawQuad.TopLeft - new Vector2(200f, 0f)));
AddStep("end drag", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("all text selected", () => textBox.SelectedText, () => Is.EqualTo(textBox.Text));
}

[Test]
public void TestSelectAll()
{
Expand Down
24 changes: 23 additions & 1 deletion osu.Framework/Graphics/UserInterface/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ protected override void OnDrag(DragEvent e)

FinalizeImeComposition(true);

if (ignoreOngoingDragSelection)
if (ignoreOngoingDragSelection || tripleClickOngoing)
return;

var lastSelectionBounds = getTextSelectionBounds();
Expand Down Expand Up @@ -1349,8 +1349,12 @@ protected override void OnDrag(DragEvent e)
onTextSelectionChanged(doubleClickWord != null ? TextSelectionType.Word : TextSelectionType.Character, lastSelectionBounds);
}

private double? lastDoubleClickTime;

protected override bool OnDoubleClick(DoubleClickEvent e)
{
lastDoubleClickTime = Time.Current;

FinalizeImeComposition(true);

var lastSelectionBounds = getTextSelectionBounds();
Expand Down Expand Up @@ -1396,6 +1400,8 @@ private static int findSeparatorIndex(string input, int searchPos, int direction
return -1;
}

private bool tripleClickOngoing;

protected override bool OnMouseDown(MouseDownEvent e)
{
if (ReadOnly)
Expand All @@ -1405,6 +1411,21 @@ protected override bool OnMouseDown(MouseDownEvent e)

var lastSelectionBounds = getTextSelectionBounds();

float tripleClickTime = GetContainingInputManager().AsNonNull().GetButtonEventManagerFor(e.Button).DoubleClickTime;

if (lastDoubleClickTime != null && Time.Current - lastDoubleClickTime < tripleClickTime)
{
lastDoubleClickTime = null;

SelectAll();

onTextSelectionChanged(TextSelectionType.All, lastSelectionBounds);

tripleClickOngoing = true;

return true;
}

selectionStart = selectionEnd = getCharacterClosestTo(e.MousePosition);

cursorAndLayout.Invalidate();
Expand All @@ -1417,6 +1438,7 @@ protected override bool OnMouseDown(MouseDownEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
doubleClickWord = null;
tripleClickOngoing = false;
}

protected override void OnFocusLost(FocusLostEvent e)
Expand Down
Loading