Skip to content

Commit

Permalink
Move isMacOs function
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Oct 24, 2023
1 parent 96394f7 commit 24a5617
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 2 additions & 10 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 @@ -193,7 +194,6 @@ export class Editor3Component extends React.Component<IProps, IState> {
this.onDragOver = this.onDragOver.bind(this);
this.handleKeyCommand = this.handleKeyCommand.bind(this);
this.handleBeforeInput = this.handleBeforeInput.bind(this);
this.isMacOS = this.isMacOS.bind(this);
this.keyBindingFn = this.keyBindingFn.bind(this);
this.handleDropOnEditor = this.handleDropOnEditor.bind(this);
this.spellcheck = this.spellcheck.bind(this);
Expand Down Expand Up @@ -279,18 +279,10 @@ export class Editor3Component extends React.Component<IProps, IState> {
}
}

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

return false;
}

keyBindingFn(e) {
const {key, shiftKey, ctrlKey, metaKey} = e;
const selectionState = this.props.editorState.getSelection();
const modifierKey = this.isMacOS() ? metaKey : ctrlKey;
const modifierKey = isMacOS() ? metaKey : ctrlKey;

if (
key === 'k'
Expand Down
12 changes: 12 additions & 0 deletions scripts/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ 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 24a5617

Please sign in to comment.