Added save shortcut support to Code Injection (#19660)

fixes DES-92
This commit is contained in:
Sodbileg Gansukh 2024-02-06 18:03:00 +07:00 committed by GitHub
parent d59775cb66
commit 65e9900578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,5 @@
import NiceModal, {useModal} from '@ebay/nice-modal-react';
import React, {useMemo, useRef, useState} from 'react';
import React, {useEffect, useMemo, useRef, useState} from 'react';
import useSettingGroup from '../../../../hooks/useSettingGroup';
import {ButtonGroup, CodeEditor, Heading, Modal, TabView} from '@tryghost/admin-x-design-system';
import {ReactCodeMirrorRef} from '@uiw/react-codemirror';
@ -63,6 +63,19 @@ const CodeModal: React.FC<CodeModalProps> = ({afterClose}) => {
const {savingTitle, isSaving, onSaveClick} = useSaveButton(handleSave, true);
useEffect(() => {
const handleCMDS = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key === 's') {
e.preventDefault();
onSaveClick();
}
};
window.addEventListener('keydown', handleCMDS);
return () => {
window.removeEventListener('keydown', handleCMDS);
};
});
return <Modal
afterClose={afterClose}
backDropClick={false}