Skip to content

Commit 1effa70

Browse files
committed
feat(TextBox): Add keyboard command capability to macOS TextBox
1 parent cecc2a8 commit 1effa70

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.macOS.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,44 @@ public TextBoxView(TextBox textBox)
2525
Initialize();
2626
}
2727

28+
public override bool PerformKeyEquivalent(NSEvent theEvent)
29+
{
30+
if (theEvent.Type == NSEventType.KeyDown)
31+
{
32+
if ((theEvent.ModifierFlags & NSEventModifierMask.DeviceIndependentModifierFlagsMask) == NSEventModifierMask.CommandKeyMask)
33+
{
34+
var selectorName = theEvent.CharactersIgnoringModifiers.ToLowerInvariant() switch
35+
{
36+
"x" => "cut:",
37+
"c" => "copy:",
38+
"v" => "paste:",
39+
"z" => "undo:",
40+
"a" => "selectAll:",
41+
_ => string.Empty,
42+
};
43+
44+
if (!string.IsNullOrWhiteSpace(selectorName))
45+
{
46+
if (NSApplication.SharedApplication.SendAction(new ObjCRuntime.Selector(selectorName), null, this))
47+
{
48+
return true;
49+
}
50+
}
51+
}
52+
else if ((theEvent.ModifierFlags & NSEventModifierMask.DeviceIndependentModifierFlagsMask) == (NSEventModifierMask.CommandKeyMask | NSEventModifierMask.ShiftKeyMask))
53+
{
54+
if (theEvent.CharactersIgnoringModifiers.ToLowerInvariant() == "z")
55+
{
56+
if (NSApplication.SharedApplication.SendAction(new ObjCRuntime.Selector("redo:"), null, this))
57+
{
58+
return true;
59+
}
60+
}
61+
}
62+
}
2863

64+
return base.PerformKeyEquivalent(theEvent);
65+
}
2966
private void OnEditingChanged(object sender, EventArgs e)
3067
{
3168
OnTextChanged();

0 commit comments

Comments
 (0)