Skip to content

Commit

Permalink
Added save shortcut support to Code Injection (TryGhost#19660)
Browse files Browse the repository at this point in the history
fixes DES-92
  • Loading branch information
minimaluminium authored Feb 6, 2024
1 parent d59775c commit 65e9900
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 65e9900

Please sign in to comment.