Skip to content

Commit 30fa82f

Browse files
committed
Implement basic hotkeys for undo-redo
Addresses #2
1 parent a205a06 commit 30fa82f

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

app/components/ui/Overlay.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
1313
import { atomWithStorage } from 'jotai/utils';
1414
import { useEffect, useRef, useState } from 'react';
15+
import { useHotkeys } from 'react-hotkeys-hook';
1516
import { Button } from '~/components/catalyst/button';
1617
import {
1718
Dialog,
@@ -26,6 +27,7 @@ import {
2627
DropdownItem,
2728
DropdownLabel,
2829
DropdownMenu,
30+
DropdownShortcut,
2931
} from '~/components/catalyst/dropdown';
3032
import {
3133
emptyPipeline,
@@ -149,6 +151,10 @@ export function OverlayUI() {
149151
setIsSettingsOpen(false);
150152
};
151153

154+
// add hotkeys hooks
155+
useHotkeys('ctrl+z, command+z', undo, [undo]);
156+
useHotkeys('ctrl+y, command+y', redo, [redo]);
157+
152158
return (
153159
<div className="fixed pointer-events-none my-6 px-4 z-10 h-screen w-screen bg-transparent">
154160
<div className="flex justify-between w-full h-fit">
@@ -187,6 +193,7 @@ export function OverlayUI() {
187193
>
188194
<ArrowUturnLeftIcon aria-hidden="true" className="h-5 w-5" />
189195
<DropdownLabel>Undo</DropdownLabel>
196+
<DropdownShortcut keys="⌃Z" />
190197
</DropdownItem>
191198

192199
<DropdownItem
@@ -196,6 +203,7 @@ export function OverlayUI() {
196203
>
197204
<ArrowUturnRightIcon aria-hidden="true" className="h-5 w-5" />
198205
<DropdownLabel>Redo</DropdownLabel>
206+
<DropdownShortcut keys="⌃Y" />
199207
</DropdownItem>
200208

201209
<DropdownDivider />

bun.lockb

454 Bytes
Binary file not shown.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"react": "^18.3.1",
3838
"react-dom": "^18.3.1",
3939
"react-dropzone": "^14.2.3",
40+
"react-hotkeys-hook": "^4.5.1",
4041
"react-markdown": "^9.0.1",
4142
"remark-breaks": "^4.0.0",
4243
"remark-gfm": "^4.0.0"

0 commit comments

Comments
 (0)