feat: select all button and key combination
This commit is contained in:
parent
27dc92ccff
commit
23efc8289c
2 changed files with 45 additions and 1 deletions
|
|
@ -433,6 +433,21 @@ function Canvas() {
|
||||||
setBlocks((prev) => prev.filter((b) => !selectionCoords.some(([x2, y2]) => x2 === b.x && y2 === b.y)));
|
setBlocks((prev) => prev.filter((b) => !selectionCoords.some(([x2, y2]) => x2 === b.x && y2 === b.y)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "a": {
|
||||||
|
if (!e.ctrlKey) return;
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const newSelection: CoordinateArray = [];
|
||||||
|
|
||||||
|
for (let x = canvasSize.minX; x < canvasSize.maxX; x++) {
|
||||||
|
for (let y = canvasSize.minY; y < canvasSize.maxY; y++) {
|
||||||
|
newSelection.push([x, y]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectionCoords(newSelection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "c": {
|
case "c": {
|
||||||
if (!e.ctrlKey) return;
|
if (!e.ctrlKey) return;
|
||||||
clipboard.copy(selectionCoords, blocks);
|
clipboard.copy(selectionCoords, blocks);
|
||||||
|
|
@ -487,7 +502,19 @@ function Canvas() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[tool, blocks, selectionCoords, selectionLayerBlocks, blockData, setBlocks, setCssCursor, setSelectionLayerBlocks, setTool]
|
[
|
||||||
|
tool,
|
||||||
|
blocks,
|
||||||
|
selectionCoords,
|
||||||
|
selectionLayerBlocks,
|
||||||
|
canvasSize,
|
||||||
|
blockData,
|
||||||
|
setBlocks,
|
||||||
|
setCssCursor,
|
||||||
|
setSelectionCoords,
|
||||||
|
setSelectionLayerBlocks,
|
||||||
|
setTool,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onKeyUp = useCallback(
|
const onKeyUp = useCallback(
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,27 @@ function SelectMenu() {
|
||||||
const { canvasSize } = useContext(CanvasContext);
|
const { canvasSize } = useContext(CanvasContext);
|
||||||
const { coords: selectionCoords, setCoords: setSelectionCoords } = useContext(SelectionContext);
|
const { coords: selectionCoords, setCoords: setSelectionCoords } = useContext(SelectionContext);
|
||||||
|
|
||||||
|
// Add every block within the canvas size to the temporary array
|
||||||
|
const selectAll = () => {
|
||||||
|
const newSelection: CoordinateArray = [];
|
||||||
|
|
||||||
|
for (let x = canvasSize.minX; x < canvasSize.maxX; x++) {
|
||||||
|
for (let y = canvasSize.minY; y < canvasSize.maxY; y++) {
|
||||||
|
newSelection.push([x, y]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectionCoords(newSelection);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenubarMenu>
|
<MenubarMenu>
|
||||||
<MenubarTrigger>Select</MenubarTrigger>
|
<MenubarTrigger>Select</MenubarTrigger>
|
||||||
<MenubarContent>
|
<MenubarContent>
|
||||||
|
<MenubarItem onClick={selectAll}>
|
||||||
|
All
|
||||||
|
<MenubarShortcut>Ctrl A</MenubarShortcut>
|
||||||
|
</MenubarItem>
|
||||||
<MenubarItem onClick={() => setSelectionCoords([])}>Clear</MenubarItem>
|
<MenubarItem onClick={() => setSelectionCoords([])}>Clear</MenubarItem>
|
||||||
</MenubarContent>
|
</MenubarContent>
|
||||||
</MenubarMenu>
|
</MenubarMenu>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue