diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 161799981c..755d27a0a5 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -503,6 +503,7 @@ type ownwin: NSWindow; popup_parent: HWND; // if not 0, indicates that we should set the popup parent overlay: NSView; + function performKeyEquivalent(event: NSEvent): Boolean; override; procedure resolvePopupParent(); message 'resolvePopupParent'; function lclOwnWindow: NSWindow; message 'lclOwnWindow'; procedure lclSetFrame(const r: TRect); override; @@ -1359,6 +1360,16 @@ begin callback.DidResignKeyNotification; end; +function TCocoaWindowContent.performKeyEquivalent(event: NSEvent): Boolean; +begin + // this event servers all TextEdit, ComboBoxes and Memos on a form. + // to do short keys for copy, paste, cut, etc... + Result := false; + NSResponderHotKeys(self, event, Result); + if not Result then + Result:=inherited performKeyEquivalent(event); +end; + procedure TCocoaWindowContent.resolvePopupParent(); var lWindow: NSWindow; diff --git a/lcl/interfaces/cocoa/cocoautils.pas b/lcl/interfaces/cocoa/cocoautils.pas index d6ca192250..62a7d1808c 100644 --- a/lcl/interfaces/cocoa/cocoautils.pas +++ b/lcl/interfaces/cocoa/cocoautils.pas @@ -95,6 +95,8 @@ function CFStringToData(AString: CFStringRef; Encoding: CFStringEncoding = DEFAU function GetCurrentEventTime: double; function GetMacOSXVersion: Integer; +procedure NSResponderHotKeys(trg: NSResponder; event: NSEvent; var handled: Boolean); + implementation procedure ColorToRGBFloat(cl: TColorRef; var r,g,b: Single); inline; @@ -699,5 +701,30 @@ begin Result := lMajor*$10000 + lMinor*$100 + lFix; end; +procedure NSResponderHotKeys(trg: NSResponder; event: NSEvent; var handled: Boolean); +begin + // todo: system keys could be overriden. thus need to review the current + // keyboard configuration first. See "Key Bindings" at + // https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html + + handled := false; + if (event.type_ = NSKeyDown) then + begin + if ((event.modifierFlags and NSCommandKeyMask) = 0) then Exit; + + if Assigned(event.charactersIgnoringModifiers.UTF8String) then + begin + case event.charactersIgnoringModifiers.UTF8String^ of + 'Z': handled := NSApplication(NSApp).sendAction_to_from(objcselector('redo:'), nil, trg); + 'a': handled := NSApplication(NSApp).sendAction_to_from(objcselector('selectAll:'), nil, trg); + 'c': handled := NSApplication(NSApp).sendAction_to_from(objcselector('copy:'), nil, trg); + 'v': handled := NSApplication(NSApp).sendAction_to_from(objcselector('paste:'), nil, trg); + 'x': handled := NSApplication(NSApp).sendAction_to_from(objcselector('cut:'), nil, trg); + 'z': handled := NSApplication(NSApp).sendAction_to_from(objcselector('undo:'), nil, trg); + end; + end; + end; +end; + end.