Skip to content

Commit 6ec0f70

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
feat(undo): Add keyboard shortcuts (Cmd/Ctrl+Z)
1 parent 46cf456 commit 6ec0f70

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/App.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ function App() {
363363
resetTrigger: pdbId
364364
});
365365

366+
// Keyboard Shortcuts for Undo/Redo
367+
useEffect(() => {
368+
const handleKeyDown = (e: KeyboardEvent) => {
369+
// Ignore if typing in an input or textarea
370+
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
371+
return;
372+
}
373+
374+
const isMod = e.metaKey || e.ctrlKey;
375+
if (isMod && e.key.toLowerCase() === 'z') {
376+
e.preventDefault();
377+
if (e.shiftKey) {
378+
if (canRedo) redo();
379+
} else {
380+
if (canUndo) undo();
381+
}
382+
}
383+
};
384+
385+
window.addEventListener('keydown', handleKeyDown);
386+
return () => window.removeEventListener('keydown', handleKeyDown);
387+
}, [undo, redo, canUndo, canRedo]);
388+
366389
// --- DERIVED STATE (Dr. AI V4) ---
367390
const structureStats = useMemo(() => {
368391
const chainCount = chains.length;

0 commit comments

Comments
 (0)