Skip to content

Commit 7557b55

Browse files
committed
add keyboard listener
1 parent 27108aa commit 7557b55

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

components/SnippetToolbar.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { useAsyncCallback, useOnline } from 'actionsack'
2+
import { useAsyncCallback, useOnline, useKeyboardListener } from 'actionsack'
33

44
import Button from './Button'
55
import Toolbar from './Toolbar'
@@ -51,6 +51,29 @@ function DuplicateButton(props) {
5151
)
5252
}
5353

54+
function SaveButton({ loading, onClick }) {
55+
useKeyboardListener('⌥-s', e => {
56+
e.preventDefault()
57+
onClick()
58+
})
59+
60+
return (
61+
<Button
62+
border
63+
large
64+
center
65+
color={COLORS.GREEN}
66+
onClick={onClick}
67+
data-cy="save-button"
68+
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
69+
title="Save"
70+
disabled={loading}
71+
>
72+
{loading ? 'Saving…' : 'Save'}
73+
</Button>
74+
)
75+
}
76+
5477
function SnippetToolbar({
5578
toggleVisibility,
5679
isVisible,
@@ -108,21 +131,8 @@ function SnippetToolbar({
108131
}}
109132
>
110133
<div className="flex">
134+
<SaveButton loading={loading} onClick={saveSnippet} />
111135
<Button
112-
border
113-
large
114-
center
115-
color={COLORS.GREEN}
116-
onClick={saveSnippet}
117-
data-cy="save-button"
118-
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
119-
title="Save"
120-
disabled={loading}
121-
>
122-
{loading ? 'Saving…' : 'Save'}
123-
</Button>
124-
<Button
125-
id="save-menu"
126136
title="Save menu dropdown"
127137
border
128138
large

pages/about.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ export default function About() {
144144
<kbd>⇧ ⌘ S</kbd>
145145
</td>
146146
</tr>
147+
<tr>
148+
<td>Save snippet</td>
149+
<td>
150+
<kbd>⌥ S</kbd>
151+
</td>
152+
</tr>
147153
<tr>
148154
<td>Copy image to clipboard</td>
149155
<td>

0 commit comments

Comments
 (0)