overleaf/services/web/frontend/js/features/pdf-preview/components/shortcuts.js
Alf Eaton 4843288b50 Merge pull request #9312 from overleaf/ds-remove-keyShortCut
Remove keyShortCut from compile function options

GitOrigin-RevId: 31b13be5fd6742419d4147b89ef281b1b30227fb
2022-08-22 08:03:49 +00:00

39 lines
958 B
JavaScript

import { useCallback } from 'react'
import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
import PropTypes from 'prop-types'
export const Shortcuts = ({ children }) => {
const { startCompile } = useDetachCompileContext()
const handleKeyDown = useCallback(
event => {
if (event.metaKey) {
switch (event.key) {
case 's':
case 'Enter':
event.preventDefault()
startCompile()
break
}
} else if (event.ctrlKey) {
switch (event.key) {
case '.':
event.preventDefault()
startCompile()
break
}
}
},
[startCompile]
)
return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<div onKeyDown={handleKeyDown} role="tabpanel" tabIndex="0">
{children}
</div>
)
}
Shortcuts.propTypes = {
children: PropTypes.node,
}