Skip to content

Commit

Permalink
Merge pull request #101 from khalidh223/98-bugfix-dragging-to-edge
Browse files Browse the repository at this point in the history
#98: Fixes bug where dragging mouse off canvas doesn't release click to allow a second mark to be made
  • Loading branch information
khalidh223 authored Dec 22, 2023
2 parents 7d56d30 + 1419912 commit 02253bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/canvas/DrawCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,21 @@ const setupCanvasListeners = (
lastCoords.current = { x: event.offsetX, y: event.offsetY }
}

const onMouseLeave = () => {
drawingRef.current = false;
}

canvas.addEventListener("mousedown", onMouseDown)
canvas.addEventListener("mouseup", stopDrawing)
canvas.addEventListener("mousemove", onMouseMove)
canvas.addEventListener("mouseleave", onMouseLeave)

return () => {
if (canvas) {
canvas.removeEventListener("mousedown", onMouseDown)
canvas.removeEventListener("mouseup", stopDrawing)
canvas.removeEventListener("mousemove", onMouseMove)
canvas.removeEventListener("mouseleave", onMouseLeave)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-artist",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 02253bf

Please sign in to comment.