Skip to content

Commit

Permalink
Merge pull request #33 from low-earth-orbit/deleteShortcut
Browse files Browse the repository at this point in the history
Delete shortcut (close #29)
  • Loading branch information
low-earth-orbit authored Sep 1, 2024
2 parents 8849d23 + c49756f commit f8d54ef
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ export default function Canvas() {
localStorage.setItem("canvasState", JSON.stringify(canvasObjects));
}, [canvasObjects]);

// keyboard shortcut
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Delete" || event.key === "Backspace") {
handleDelete();
}
};

// Add event listener for keydown
document.addEventListener("keydown", handleKeyDown);

// Clean up event listener on component unmount
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
}, [selectedObjectId, canvasObjects, handleDelete]);

function updateStyle(property: keyof CanvasObjectType, value: any) {
// Dynamically update state
if (property === "strokeWidth") {
Expand Down

0 comments on commit f8d54ef

Please sign in to comment.