improve keyboard shortcuts (#1159)

main
Michael Fix 4 years ago committed by GitHub
parent 43cfb5ae6a
commit e6950a0029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useCopyTextHandler, useAsyncCallback } from 'actionsack' import { useCopyTextHandler, useAsyncCallback, useKeyboardListener } from 'actionsack'
import morph from 'morphmorph' import morph from 'morphmorph'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
@ -64,8 +64,15 @@ function CopyMenu({ isVisible, toggleVisibility, copyImage, carbonRef }) {
) )
const [copy, { loading }] = useAsyncCallback(async (...args) => { const [copy, { loading }] = useAsyncCallback(async (...args) => {
await copyImage(...args) if (clipboardSupported) {
showCopied() await copyImage(...args)
showCopied()
}
})
useKeyboardListener('⌘-⇧-c', e => {
e.preventDefault()
copy(e)
}) })
return ( return (

@ -34,6 +34,13 @@ function useSafari() {
return isSafari return isSafari
} }
function preventDefault(fn) {
return e => {
e.preventDefault()
return fn(e)
}
}
function ExportMenu({ function ExportMenu({
backgroundImage, backgroundImage,
onChange, onChange,
@ -48,7 +55,6 @@ function ExportMenu({
const input = React.useRef() const input = React.useRef()
const [exportImage, { loading }] = useAsyncCallback(exp) const [exportImage, { loading }] = useAsyncCallback(exp)
useKeyboardListener('⌘-⇧-e', () => exportImage())
const disablePNG = isSafari && (tooLarge || !online) const disablePNG = isSafari && (tooLarge || !online)
@ -59,6 +65,9 @@ function ExportMenu({
filename: input.current && input.current.value, filename: input.current && input.current.value,
}) })
useKeyboardListener('⌘-⇧-e', preventDefault(handleExport('png')))
useKeyboardListener('⌘-⇧-s', preventDefault(handleExport('svg')))
return ( return (
<div className="export-menu-container"> <div className="export-menu-container">
<div className="flex"> <div className="flex">

@ -99,6 +99,18 @@ export default function About() {
<kbd> E</kbd> <kbd> E</kbd>
</td> </td>
</tr> </tr>
<tr>
<td>Export as SVG</td>
<td>
<kbd> S</kbd>
</td>
</tr>
<tr>
<td>Copy image to clipboard</td>
<td>
<kbd> C</kbd>
</td>
</tr>
<tr> <tr>
<td>Reset settings</td> <td>Reset settings</td>
<td> <td>

Loading…
Cancel
Save