1414using SamplesApp . UITests ;
1515using Uno . Disposables ;
1616using Uno . Extensions ;
17+ using Uno . UI . Helpers ;
1718using Uno . UI . RuntimeTests . Helpers ;
1819using Uno . UI . Toolkit . DevTools . Input ;
1920using Uno . UI . Xaml . Core ;
@@ -38,8 +39,8 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
3839 /// </summary>
3940 public partial class Given_TextBox
4041 {
41- // most macOS keyboard shortcuts uses Command (mapped as Window) and not Control (Ctrl)
42- private readonly VirtualKeyModifiers _platformCtrlKey = RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? VirtualKeyModifiers . Windows : VirtualKeyModifiers . Control ;
42+ // Apple platforms ( macOS, iOS, Mac Catalyst, tvOS) use Command key for standard shortcuts
43+ private readonly VirtualKeyModifiers _platformCtrlKey = DeviceTargetHelper . PlatformCommandModifier ;
4344
4445 [ TestMethod ]
4546 public async Task When_Basic_Input ( )
@@ -369,10 +370,10 @@ public async Task When_Ctrl_End_ScrollViewer_Vertical_Offset()
369370
370371 Assert . AreEqual ( 0 , ( ( ScrollViewer ) SUT . ContentElement ) . VerticalOffset ) ;
371372
372- // on macOS moving to the end of the document is done with `Command` + `Down`
373- var macOS = OperatingSystem . IsMacOS ( ) ;
374- var key = macOS ? VirtualKey . Down : VirtualKey . End ;
375- var mod = macOS ? VirtualKeyModifiers . Windows : VirtualKeyModifiers . Control ;
373+ // on Apple platforms moving to the end of the document is done with `Command` + `Down`
374+ var isAppleKeyboard = DeviceTargetHelper . UsesAppleKeyboardLayout ;
375+ var key = isAppleKeyboard ? VirtualKey . Down : VirtualKey . End ;
376+ var mod = isAppleKeyboard ? VirtualKeyModifiers . Windows : VirtualKeyModifiers . Control ;
376377 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , key , mod ) ) ;
377378 await WindowHelper . WaitForIdle ( ) ;
378379
@@ -463,14 +464,14 @@ public async Task When_Ctrl_Home_End()
463464 SUT . Focus ( FocusState . Programmatic ) ;
464465 await WindowHelper . WaitForIdle ( ) ;
465466
466- var key = OperatingSystem . IsMacOS ( ) ? VirtualKey . Down : VirtualKey . End ;
467+ var key = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKey . Down : VirtualKey . End ;
467468 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , key , _platformCtrlKey ) ) ;
468469 await WindowHelper . WaitForIdle ( ) ;
469470
470471 Assert . AreEqual ( SUT . Text . Length , SUT . SelectionStart ) ;
471472 Assert . AreEqual ( 0 , SUT . SelectionLength ) ;
472473
473- key = OperatingSystem . IsMacOS ( ) ? VirtualKey . Up : VirtualKey . Home ;
474+ key = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKey . Up : VirtualKey . Home ;
474475 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , key , _platformCtrlKey ) ) ;
475476 await WindowHelper . WaitForIdle ( ) ;
476477
@@ -499,8 +500,8 @@ public async Task When_Ctrl_Delete()
499500 Assert . AreEqual ( 0 , SUT . SelectionStart ) ;
500501 Assert . AreEqual ( 0 , SUT . SelectionLength ) ;
501502
502- // on macOS it's option (menu/alt) and backspace to delete a word
503- var mod = OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
503+ // on Apple platforms it's option (menu/alt) and backspace to delete a word
504+ var mod = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
504505 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Delete , mod ) ) ;
505506 await WindowHelper . WaitForIdle ( ) ;
506507
@@ -537,8 +538,8 @@ public async Task When_Ctrl_Backspace()
537538 SUT . Select ( SUT . Text . Length , 0 ) ;
538539 await WindowHelper . WaitForIdle ( ) ;
539540
540- // on macOS it's option (menu/alt) and backspace to delete a word
541- var mod = OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
541+ // on Apple platforms it's option (menu/alt) and backspace to delete a word
542+ var mod = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
542543 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Back , mod ) ) ;
543544 await WindowHelper . WaitForIdle ( ) ;
544545
@@ -610,8 +611,8 @@ public async Task When_Selection_With_Keyboard_NoMod_Ctrl_And_Shift()
610611 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Home , VirtualKeyModifiers . None ) ) ;
611612 await WindowHelper . WaitForIdle ( ) ;
612613
613- // on macOS you use `option` (alt/menu) and `right` to move to the next work
614- var mod = OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
614+ // on Apple platforms you use `option` (alt/menu) and `right` to move to the next word
615+ var mod = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
615616 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Right , mod ) ) ;
616617 await WindowHelper . WaitForIdle ( ) ;
617618 Assert . AreEqual ( 6 , SUT . SelectionStart ) ;
@@ -1003,8 +1004,8 @@ public async Task When_Scrolling_Updates_After_Backspace()
10031004 Assert . AreEqual ( svRight , LayoutInformation . GetLayoutSlot ( SUT ) . Right ) ;
10041005 }
10051006
1006- // on macOS we use `option` (menu/alt) + `delete` to remove word at the left
1007- var mod = OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
1007+ // on Apple platforms we use `option` (menu/alt) + `delete` to remove word at the left
1008+ var mod = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
10081009 for ( var i = 0 ; i < 10 ; i ++ )
10091010 {
10101011 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Back , mod ) ) ;
@@ -1930,9 +1931,9 @@ public async Task When_NonAscii_Characters()
19301931 [ CombinatorialData ]
19311932 public async Task When_Copy_Paste ( bool useInsert )
19321933 {
1933- if ( useInsert && OperatingSystem . IsMacOS ( ) )
1934+ if ( useInsert && DeviceTargetHelper . UsesAppleKeyboardLayout )
19341935 {
1935- Assert . Inconclusive ( "There's no `Insert` key on Mac keyboards" ) ;
1936+ Assert . Inconclusive ( "There's no `Insert` key on Apple keyboards" ) ;
19361937 // it's replaced by the `fn` key, which is a modifier
19371938 }
19381939 if ( OperatingSystem . IsBrowser ( ) )
@@ -2539,8 +2540,8 @@ public async Task When_Multiline_Keyboard_Chunking()
25392540 Assert . AreEqual ( 0 , SUT . SelectionStart ) ;
25402541 Assert . AreEqual ( 0 , SUT . SelectionLength ) ;
25412542
2542- // on macOS selecting the next word is `shift` + `option` (alt/menu) + `right`
2543- var mod = VirtualKeyModifiers . Shift | ( OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ) ;
2543+ // on Apple platforms selecting the next word is `shift` + `option` (alt/menu) + `right`
2544+ var mod = VirtualKeyModifiers . Shift | ( DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ) ;
25442545 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Right , mod ) ) ;
25452546 await WindowHelper . WaitForIdle ( ) ;
25462547 Assert . AreEqual ( 0 , SUT . SelectionStart ) ;
@@ -4189,8 +4190,8 @@ public async Task When_Ctrl_Delete_Undo_Redo()
41894190 SUT . Focus ( FocusState . Programmatic ) ;
41904191 await WindowHelper . WaitForIdle ( ) ;
41914192
4192- // on macOS it's option (menu/alt) and backspace to delete a word
4193- var mod = OperatingSystem . IsMacOS ( ) ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
4193+ // on Apple platforms it's option (menu/alt) and backspace to delete a word
4194+ var mod = DeviceTargetHelper . UsesAppleKeyboardLayout ? VirtualKeyModifiers . Menu : VirtualKeyModifiers . Control ;
41944195 SUT . SafeRaiseEvent ( UIElement . KeyDownEvent , new KeyRoutedEventArgs ( SUT , VirtualKey . Delete , mod ) ) ;
41954196 await WindowHelper . WaitForIdle ( ) ;
41964197
0 commit comments