Skip to content

Commit

Permalink
MacOS shortcut for links in editor3 (#4346)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored and petrjasek committed Oct 24, 2023
1 parent 392bf99 commit f8f965e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/core/editor3/components/Editor3Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -278,12 +279,13 @@ export class Editor3Component extends React.Component<IProps, IState> {
}

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
) {
Expand Down
5 changes: 5 additions & 0 deletions scripts/core/editor3/components/links/LinkInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export class LinkInputComponent extends React.Component<any, any> {
>
<div style={{padding: '3.2rem 1.6rem'}}>
<input
onKeyDown={(e) => {
if (e.key === 'Enter') {
this.onSubmit(linkTypes.href);
}
}}
type="url"
ref={(el) => {
this.inputElement = el;
Expand Down
11 changes: 11 additions & 0 deletions scripts/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f8f965e

Please sign in to comment.