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 Oct 24, 2023
1 parent 1bd7315 commit 8dd0036
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 @@ -279,12 +280,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 @@ -188,6 +188,11 @@ export class LinkInputComponent extends React.Component<IProps, 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 @@ -17,6 +17,17 @@ function applyTranslations(translations) {
window.translations = translations;
}

export function isMacOS() {
if (
navigator.userAgent.toLowerCase().includes('macintosh')
|| navigator.userAgent.toLowerCase().includes('mac os')
) {
return true;
}

return false;
}

function requestListener() {
const translations = JSON.parse(this.responseText);

Expand Down

0 comments on commit 8dd0036

Please sign in to comment.