feat: select all button and key combination

This commit is contained in:
trafficlunar 2025-01-31 14:17:56 +00:00
parent 27dc92ccff
commit 23efc8289c
2 changed files with 45 additions and 1 deletions

View file

@ -433,6 +433,21 @@ function Canvas() {
setBlocks((prev) => prev.filter((b) => !selectionCoords.some(([x2, y2]) => x2 === b.x && y2 === b.y)));
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": {
if (!e.ctrlKey) return;
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(

View file

@ -11,10 +11,27 @@ function SelectMenu() {
const { canvasSize } = useContext(CanvasContext);
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 (
<MenubarMenu>
<MenubarTrigger>Select</MenubarTrigger>
<MenubarContent>
<MenubarItem onClick={selectAll}>
All
<MenubarShortcut>Ctrl A</MenubarShortcut>
</MenubarItem>
<MenubarItem onClick={() => setSelectionCoords([])}>Clear</MenubarItem>
</MenubarContent>
</MenubarMenu>