From 1b379d80cc3acd86be5ca6f9a2e9f0c3968b974d Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Sun, 19 Jan 2025 13:32:59 +0000 Subject: [PATCH] feat: hold shift with magic wand tool to add to existing selection --- src/components/canvas/Canvas.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/canvas/Canvas.tsx b/src/components/canvas/Canvas.tsx index ac7d245..d8e2115 100644 --- a/src/components/canvas/Canvas.tsx +++ b/src/components/canvas/Canvas.tsx @@ -43,6 +43,7 @@ function Canvas() { const dragStartCoordsRef = useRef(); const holdingAltRef = useRef(false); + const holdingShiftRef = useRef(false); const oldToolRef = useRef(); const selectionCoordsRef = useRef(selectionCoords); @@ -339,6 +340,11 @@ function Canvas() { if (holdingAltRef.current) { // If holding alt, remove new magic wand selection return prev.filter(([x, y]) => !result.some(([x2, y2]) => x2 === x && y2 === y)); + } else if (holdingShiftRef.current) { + // If holding shift, add magic wand selection to existing selection + const existing = new Set(prev.map(([x, y]) => `${x},${y}`)); + const newCoords = result.filter(([x, y]) => !existing.has(`${x},${y}`)); + return [...prev, ...newCoords]; } // If not holding alt or shift, replace the existing selection with the magic wand selection @@ -371,6 +377,9 @@ function Canvas() { setTool("hand"); setCssCursor("grabbing"); break; + case "Shift": + holdingShiftRef.current = true; + break; case "Alt": holdingAltRef.current = true; if (tool === "zoom") setCssCursor("zoom-out"); @@ -417,6 +426,9 @@ function Canvas() { setCssCursor("grab"); setTool(oldToolRef.current); break; + case "Shift": + holdingShiftRef.current = false; + break; case "Alt": holdingAltRef.current = false; setCssCursor("zoom-in");