From b8291540fc5a0e3f02e8d1a3e0c4c2fd2e8b565d Mon Sep 17 00:00:00 2001 From: thecalcc Date: Mon, 23 Oct 2023 15:37:15 +0300 Subject: [PATCH] MacOS shortcut for links in editor3 --- .../core/editor3/components/Editor3Component.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/core/editor3/components/Editor3Component.tsx b/scripts/core/editor3/components/Editor3Component.tsx index 92ac479a67..a367d33c89 100644 --- a/scripts/core/editor3/components/Editor3Component.tsx +++ b/scripts/core/editor3/components/Editor3Component.tsx @@ -278,13 +278,22 @@ export class Editor3Component extends React.Component { } } + isMacOS() { + if (navigator.userAgent.indexOf('Mac') != -1) { + return true; + } + + return false; + } + keyBindingFn(e) { - const {key, shiftKey, ctrlKey} = e; + const {key, shiftKey, ctrlKey, metaKey} = e; const selectionState = this.props.editorState.getSelection(); + const osBasedKeyRule = this.isMacOS() ? metaKey : ctrlKey; if ( key === 'k' - && ctrlKey + && osBasedKeyRule && this.props.editorFormat.includes('link') && selectionState.isCollapsed() !== true ) {