diff --git a/client/common/useKeyDownHandlers.js b/client/common/useKeyDownHandlers.js index ce57ab5925..8a45e09c84 100644 --- a/client/common/useKeyDownHandlers.js +++ b/client/common/useKeyDownHandlers.js @@ -32,8 +32,13 @@ export default function useKeyDownHandlers(keyHandlers) { if (!e.key) return; const isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1; const isCtrl = isMac ? e.metaKey : e.ctrlKey; + if (e.shiftKey && isCtrl) { handlers.current[`ctrl-shift-${e.key.toLowerCase()}`]?.(e); + } else if (e.altKey && e.shiftKey) { + handlers.current[`alt-shift-${e.key.toLowerCase()}`]?.(e); + } else if (e.altKey) { + handlers.current[`alt-${e.key.toLowerCase()}`]?.(e); } else if (isCtrl) { handlers.current[`ctrl-${e.key.toLowerCase()}`]?.(e); } diff --git a/client/modules/IDE/components/IDEKeyHandlers.jsx b/client/modules/IDE/components/IDEKeyHandlers.jsx index c7a285e627..376021d273 100644 --- a/client/modules/IDE/components/IDEKeyHandlers.jsx +++ b/client/modules/IDE/components/IDEKeyHandlers.jsx @@ -2,10 +2,13 @@ import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; import { updateFileContent } from '../actions/files'; import { + closeProjectOptions, collapseConsole, collapseSidebar, expandConsole, expandSidebar, + newFile, + newFolder, showErrorModal, startSketch, stopSketch @@ -18,12 +21,14 @@ import { getIsUserOwner, getSketchOwner } from '../selectors/users'; +import { selectRootFile } from '../selectors/files'; export const useIDEKeyHandlers = ({ getContent }) => { const dispatch = useDispatch(); const sidebarIsExpanded = useSelector((state) => state.ide.sidebarIsExpanded); const consoleIsExpanded = useSelector((state) => state.ide.consoleIsExpanded); + const rootFile = useSelector(selectRootFile); const isUserOwner = useSelector(getIsUserOwner); const isAuthenticated = useSelector(getAuthenticated); @@ -75,6 +80,18 @@ export const useIDEKeyHandlers = ({ getContent }) => { 'ctrl-`': (e) => { e.preventDefault(); dispatch(consoleIsExpanded ? collapseConsole() : expandConsole()); + }, + 'alt-n': (e) => { + e.preventDefault(); + // For Creating new Files + dispatch(newFile(rootFile.id)); + setTimeout(() => dispatch(closeProjectOptions()), 0); + }, + 'alt-shift-n': (e) => { + e.preventDefault(); + // For Creating new Folder + dispatch(newFolder(rootFile.id)); + setTimeout(() => dispatch(closeProjectOptions()), 0); } }); };