feat: hold shift with magic wand tool to add to existing selection

This commit is contained in:
trafficlunar 2025-01-19 13:32:59 +00:00
parent 2f8772769d
commit 1b379d80cc

View file

@ -43,6 +43,7 @@ function Canvas() {
const dragStartCoordsRef = useRef<Position>();
const holdingAltRef = useRef(false);
const holdingShiftRef = useRef(false);
const oldToolRef = useRef<Tool>();
const selectionCoordsRef = useRef<CoordinateArray>(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");