From 65e9900578387bfa96f2e8c833082012488c872f Mon Sep 17 00:00:00 2001 From: Sodbileg Gansukh Date: Tue, 6 Feb 2024 18:03:00 +0700 Subject: [PATCH] Added save shortcut support to Code Injection (#19660) fixes DES-92 --- .../settings/advanced/code/CodeModal.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/admin-x-settings/src/components/settings/advanced/code/CodeModal.tsx b/apps/admin-x-settings/src/components/settings/advanced/code/CodeModal.tsx index 72e687166d..0bc01517db 100644 --- a/apps/admin-x-settings/src/components/settings/advanced/code/CodeModal.tsx +++ b/apps/admin-x-settings/src/components/settings/advanced/code/CodeModal.tsx @@ -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 = ({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