Adding @irev-dev's solution to register all shortcuts

This commit is contained in:
Frank Johnson
2021-09-07 21:19:29 -04:00
parent 9887eb4804
commit 678754d251
2 changed files with 19 additions and 3 deletions

View File

@@ -1,8 +1,10 @@
import { Menu } from '@headlessui/react'
import { useEffect, useState } from 'react'
import { useHotkeys } from 'react-hotkeys-hook';
import { makeStyles } from '@material-ui/core/styles'
import Dialog from '@material-ui/core/Dialog'
import { editorMenuConfig } from './menuConfig';
import { useIdeContext } from 'src/helpers/hooks/useIdeContext'
const SHORTCUT = 'ctrl+/, command+/'
@@ -16,8 +18,22 @@ const AllShortcutsModal = () => {
const classes = useStyles()
const [open, setOpen] = useState(false)
useHotkeys(SHORTCUT, () => setOpen(!open), [open])
const { state, thunkDispatch } = useIdeContext()
return (
return (<>
<div className="hidden">
<Menu>
{ editorMenuConfig.filter(menu => menu.items.length).map(menu =>
menu.items.map(item => (
<item.component
state={state}
thunkDispatch={thunkDispatch}
config={item}
key={menu.label +"-"+ item.label } />
))
)}
</Menu>
</div>
<Dialog open={open} onClose={() => setOpen(false)} className={classes.root}>
<div className="bg-ch-gray-700 font-fira-sans max-w-7xl rounded shadow-lg text-ch-gray-300 p-4">
<h2 className="text-2xl mb-4">All Shortcuts</h2>
@@ -35,7 +51,7 @@ const AllShortcutsModal = () => {
)}
</div>
</Dialog>
)
</>)
}

View File

@@ -54,7 +54,7 @@ const fileMenuConfig = {
},
{
label: 'Cook Donut',
shortcut: 'ctrl+os+d',
shortcut: 'ctrl+d, command+d',
shortcutLabel: cmdOrCtrl() + ' D',
component: (props) => {
const { config } = props