Skip to content

Commit

Permalink
Merge pull request #19318 from ramezgerges/textbox_selection_shift_tap
Browse files Browse the repository at this point in the history
fix(textbox): extend selection when on tapping when shift is held
  • Loading branch information
ramezgerges authored Jan 27, 2025
2 parents 7dec1be + db4c483 commit 0ce7d20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,45 @@ public async Task When_Pointer_Tap()
Assert.AreEqual(0, SUT.SelectionLength);
}

[TestMethod]
public async Task When_Pointer_Shift_Tap()
{
using var _ = new TextBoxFeatureConfigDisposable();

var SUT = new TextBox
{
Width = 130,
Text = "Hello world",
};

WindowHelper.WindowContent = SUT;

await WindowHelper.WaitForIdle();
await WindowHelper.WaitForLoaded(SUT);

SUT.Focus(FocusState.Programmatic);
await WindowHelper.WaitForIdle();

var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector");
using var mouse = injector.GetMouse();

mouse.MoveTo(SUT.GetAbsoluteBounds().GetCenter());
await WindowHelper.WaitForIdle();

mouse.Press();
mouse.Release();
await WindowHelper.WaitForIdle();

var selectionEnd = SUT.SelectionStart;

mouse.MoveBy(-20, 0);
mouse.Press(VirtualKeyModifiers.Shift);
mouse.Release(VirtualKeyModifiers.Shift);
await WindowHelper.WaitForIdle();

Assert.AreEqual(selectionEnd, SUT.SelectionStart + SUT.SelectionLength);
}

[TestMethod]
public async Task When_Pointer_RightClick_No_Selection()
{
Expand Down
11 changes: 10 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.pointers.skia.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using Windows.Foundation;
using Windows.System;
using Microsoft.UI.Xaml.Input;
using Uno.Extensions;
using Uno.UI.Helpers.WinUI;
Expand Down Expand Up @@ -163,7 +164,15 @@ partial void OnPointerPressedPartial(PointerRoutedEventArgs args)
{
// single click
CaretMode = CaretDisplayMode.ThumblessCaretShowing;
Select(index, 0);
if ((args.KeyModifiers & VirtualKeyModifiers.Shift) != 0)
{
var selectionInternalStart = _selection.selectionEndsAtTheStart ? _selection.start + _selection.length : _selection.start;
SelectInternal(selectionInternalStart, index - selectionInternalStart);
}
else
{
Select(index, 0);
}
_lastPointerDown = (currentPoint, 0);
}
}
Expand Down

0 comments on commit 0ce7d20

Please sign in to comment.