From 08da791da8a8c67f83f9bf5c4afe9da1bda9c075 Mon Sep 17 00:00:00 2001 From: khushal Date: Wed, 15 May 2024 18:42:53 +0530 Subject: [PATCH] rectified the delete and select twice click problem --- components/Canvas.jsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/Canvas.jsx b/components/Canvas.jsx index 4d451bd..756c788 100644 --- a/components/Canvas.jsx +++ b/components/Canvas.jsx @@ -113,6 +113,7 @@ const Canvas = () => { useEffect(()=>{ + const canvas = document.getElementById("canvas") const handleKeyDown = (event) => { setKeys(keys => new Set(keys).add(event.key)); } @@ -126,11 +127,11 @@ const Canvas = () => { }; // console.log(keys) - window.addEventListener("keydown", handleKeyDown); - window.addEventListener("keyup", handleKeyUp); + canvas.addEventListener("keydown", handleKeyDown); + canvas.addEventListener("keyup", handleKeyUp); return () => { - window.removeEventListener("keydown", handleKeyDown); - window.removeEventListener("keyup", handleKeyUp); + canvas.removeEventListener("keydown", handleKeyDown); + canvas.removeEventListener("keyup", handleKeyUp); }; },[keys])