Skip to content

Commit

Permalink
improve keyboard shortcuts (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 authored Jan 15, 2021
1 parent 43cfb5a commit e6950a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
13 changes: 10 additions & 3 deletions components/CopyMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { useRouter } from 'next/router'
import { useCopyTextHandler, useAsyncCallback } from 'actionsack'
import { useCopyTextHandler, useAsyncCallback, useKeyboardListener } from 'actionsack'
import morph from 'morphmorph'

import { COLORS } from '../lib/constants'
Expand Down Expand Up @@ -64,8 +64,15 @@ function CopyMenu({ isVisible, toggleVisibility, copyImage, carbonRef }) {
)

const [copy, { loading }] = useAsyncCallback(async (...args) => {
await copyImage(...args)
showCopied()
if (clipboardSupported) {
await copyImage(...args)
showCopied()
}
})

useKeyboardListener('⌘-⇧-c', e => {
e.preventDefault()
copy(e)
})

return (
Expand Down
11 changes: 10 additions & 1 deletion components/ExportMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function useSafari() {
return isSafari
}

function preventDefault(fn) {
return e => {
e.preventDefault()
return fn(e)
}
}

function ExportMenu({
backgroundImage,
onChange,
Expand All @@ -48,7 +55,6 @@ function ExportMenu({
const input = React.useRef()

const [exportImage, { loading }] = useAsyncCallback(exp)
useKeyboardListener('⌘-⇧-e', () => exportImage())

const disablePNG = isSafari && (tooLarge || !online)

Expand All @@ -59,6 +65,9 @@ function ExportMenu({
filename: input.current && input.current.value,
})

useKeyboardListener('⌘-⇧-e', preventDefault(handleExport('png')))
useKeyboardListener('⌘-⇧-s', preventDefault(handleExport('svg')))

return (
<div className="export-menu-container">
<div className="flex">
Expand Down
12 changes: 12 additions & 0 deletions pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ export default function About() {
<kbd>⇧ ⌘ E</kbd>
</td>
</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>
<td>Reset settings</td>
<td>
Expand Down

0 comments on commit e6950a0

Please sign in to comment.