From f8f965e1681b8550c2f2ea37c7f97200bc412912 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Tue, 24 Oct 2023 13:51:49 +0300 Subject: [PATCH] MacOS shortcut for links in editor3 (#4346) --- scripts/core/editor3/components/Editor3Component.tsx | 6 ++++-- scripts/core/editor3/components/links/LinkInput.tsx | 5 +++++ scripts/core/utils.ts | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/core/editor3/components/Editor3Component.tsx b/scripts/core/editor3/components/Editor3Component.tsx index b96e6a8219..3f48512bb4 100644 --- a/scripts/core/editor3/components/Editor3Component.tsx +++ b/scripts/core/editor3/components/Editor3Component.tsx @@ -39,6 +39,7 @@ import {handleBeforeInputHighlights} from '../helpers/handleBeforeInputHighlight import {CharacterLimitUiBehavior} from 'apps/authoring/authoring/components/CharacterCountConfigButton'; import {Editor3Autocomplete} from './Editor3Autocomplete'; import {querySelectorParent} from 'core/helpers/dom/querySelectorParent'; +import {isMacOS} from 'core/utils'; const MEDIA_TYPES_TRIGGER_DROP_ZONE = [ 'application/superdesk.item.picture', @@ -278,12 +279,13 @@ export class Editor3Component extends React.Component { } keyBindingFn(e) { - const {key, shiftKey, ctrlKey} = e; + const {key, shiftKey, ctrlKey, metaKey} = e; const selectionState = this.props.editorState.getSelection(); + const modifierKey = isMacOS() ? metaKey : ctrlKey; if ( key === 'k' - && ctrlKey + && modifierKey && this.props.editorFormat.includes('link') && selectionState.isCollapsed() !== true ) { diff --git a/scripts/core/editor3/components/links/LinkInput.tsx b/scripts/core/editor3/components/links/LinkInput.tsx index bbf66abeb6..db917d6477 100644 --- a/scripts/core/editor3/components/links/LinkInput.tsx +++ b/scripts/core/editor3/components/links/LinkInput.tsx @@ -167,6 +167,11 @@ export class LinkInputComponent extends React.Component { >
{ + if (e.key === 'Enter') { + this.onSubmit(linkTypes.href); + } + }} type="url" ref={(el) => { this.inputElement = el; diff --git a/scripts/core/utils.ts b/scripts/core/utils.ts index d6e06b2b4d..e21e9e084e 100644 --- a/scripts/core/utils.ts +++ b/scripts/core/utils.ts @@ -4,6 +4,17 @@ import {IVocabularyItem, IArticle} from 'superdesk-api'; import {assertNever} from './helpers/typescript-helpers'; import {appConfig} from 'appConfig'; +export function isMacOS() { + if ( + navigator.userAgent.toLowerCase().includes('macintosh') + || navigator.userAgent.toLowerCase().includes('mac os') + ) { + return true; + } + + return false; +} + export type IScopeApply = (fn: () => void) => void; export const i18n = gettextjs();