Skip to content

Commit

Permalink
feat(TextBox): Add keyboard command capability to macOS TextBox
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Feb 5, 2021
1 parent cecc2a8 commit 1effa70
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,44 @@ public TextBoxView(TextBox textBox)
Initialize();
}

public override bool PerformKeyEquivalent(NSEvent theEvent)
{
if (theEvent.Type == NSEventType.KeyDown)
{
if ((theEvent.ModifierFlags & NSEventModifierMask.DeviceIndependentModifierFlagsMask) == NSEventModifierMask.CommandKeyMask)
{
var selectorName = theEvent.CharactersIgnoringModifiers.ToLowerInvariant() switch
{
"x" => "cut:",
"c" => "copy:",
"v" => "paste:",
"z" => "undo:",
"a" => "selectAll:",
_ => string.Empty,
};

if (!string.IsNullOrWhiteSpace(selectorName))
{
if (NSApplication.SharedApplication.SendAction(new ObjCRuntime.Selector(selectorName), null, this))
{
return true;
}
}
}
else if ((theEvent.ModifierFlags & NSEventModifierMask.DeviceIndependentModifierFlagsMask) == (NSEventModifierMask.CommandKeyMask | NSEventModifierMask.ShiftKeyMask))
{
if (theEvent.CharactersIgnoringModifiers.ToLowerInvariant() == "z")
{
if (NSApplication.SharedApplication.SendAction(new ObjCRuntime.Selector("redo:"), null, this))
{
return true;
}
}
}
}

return base.PerformKeyEquivalent(theEvent);
}
private void OnEditingChanged(object sender, EventArgs e)
{
OnTextChanged();
Expand Down

0 comments on commit 1effa70

Please sign in to comment.