Skip to content

Commit

Permalink
fix(tests): When_Ctrl_Backspace on macOS/skia
Browse files Browse the repository at this point in the history
  • Loading branch information
spouliot committed Nov 4, 2024
1 parent 3d19d61 commit 8fc014a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,16 @@ public async Task When_Ctrl_Backspace()
SUT.Select(SUT.Text.Length, 0);
await WindowHelper.WaitForIdle();

SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Back, VirtualKeyModifiers.Control));
// on macOS it's option (menu/alt) and backspace to delete a word
var mod = OperatingSystem.IsMacOS() ? VirtualKeyModifiers.Menu : VirtualKeyModifiers.Control;
SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Back, mod));
await WindowHelper.WaitForIdle();

Assert.AreEqual("lorem ipsum ", SUT.Text);
Assert.AreEqual(SUT.Text.Length, SUT.SelectionStart);
Assert.AreEqual(0, SUT.SelectionLength);

SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Back, VirtualKeyModifiers.Control));
SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.Back, mod));
await WindowHelper.WaitForIdle();

Assert.AreEqual("lorem ", SUT.Text);
Expand Down
6 changes: 6 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ args.Key is not (VirtualKey.Up or VirtualKey.Down or VirtualKey.Left or VirtualK

private void KeyDownBack(KeyRoutedEventArgs args, ref string text, bool ctrl, bool shift, ref int selectionStart, ref int selectionLength)
{
// on macOS it is `option` + `delete` (same location as backspace on PC keyboards) that removes the previous word
if (OperatingSystem.IsMacOS())
{
ctrl = args.KeyboardModifiers.HasFlag(VirtualKeyModifiers.Menu);

Check notice on line 544 in src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs#L544

Introduce a new variable instead of reusing the parameter 'ctrl'.
}

if (HasPointerCapture)
{
return;
Expand Down

0 comments on commit 8fc014a

Please sign in to comment.