fix: selection, remove blocks when selectedBlock is "air"
This commit is contained in:
parent
123067330c
commit
c17eec6403
2 changed files with 8 additions and 6 deletions
|
|
@ -173,7 +173,7 @@ function Canvas() {
|
||||||
[dragging, coords, scale, tool, mouseCoords, onToolUse, setCoords]
|
[dragging, coords, scale, tool, mouseCoords, onToolUse, setCoords]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onMouseDown = useCallback(() => {
|
const onPointerDown = useCallback(() => {
|
||||||
dragging.current = true;
|
dragging.current = true;
|
||||||
|
|
||||||
onToolUse();
|
onToolUse();
|
||||||
|
|
@ -187,7 +187,7 @@ function Canvas() {
|
||||||
if (tool === "rectangle-select") setSelectionCoords([]);
|
if (tool === "rectangle-select") setSelectionCoords([]);
|
||||||
}, [onToolUse, updateCssCursor, mouseCoords, blocks, selectionCoords, tool, setSelectionCoords]);
|
}, [onToolUse, updateCssCursor, mouseCoords, blocks, selectionCoords, tool, setSelectionCoords]);
|
||||||
|
|
||||||
const onMouseUp = useCallback(() => {
|
const onPointerUp = useCallback(() => {
|
||||||
dragging.current = false;
|
dragging.current = false;
|
||||||
|
|
||||||
updateCssCursor();
|
updateCssCursor();
|
||||||
|
|
@ -253,10 +253,12 @@ function Canvas() {
|
||||||
setSelectionLayerBlocks([]);
|
setSelectionLayerBlocks([]);
|
||||||
break;
|
break;
|
||||||
case "Enter": {
|
case "Enter": {
|
||||||
|
if (selectionLayerBlocks.length == 0) return;
|
||||||
|
|
||||||
const combinedBlocks = [...blocks, ...selectionLayerBlocks];
|
const combinedBlocks = [...blocks, ...selectionLayerBlocks];
|
||||||
const uniqueBlocks = Array.from(new Map(combinedBlocks.map((block) => [`${block.x},${block.y}`, block])).values());
|
const uniqueBlocks = Array.from(new Map(combinedBlocks.map((block) => [`${block.x},${block.y}`, block])).values());
|
||||||
|
|
||||||
setBlocks(uniqueBlocks);
|
setBlocks(uniqueBlocks.filter((b) => b.name !== "air"));
|
||||||
setSelectionLayerBlocks([]);
|
setSelectionLayerBlocks([]);
|
||||||
|
|
||||||
addHistory(
|
addHistory(
|
||||||
|
|
@ -480,9 +482,9 @@ function Canvas() {
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onKeyUp={onKeyUp}
|
onKeyUp={onKeyUp}
|
||||||
onPointerDown={onMouseDown}
|
onPointerDown={onPointerDown}
|
||||||
onPointerMove={onPointerMove}
|
onPointerMove={onPointerMove}
|
||||||
onPointerUp={onMouseUp}
|
onPointerUp={onPointerUp}
|
||||||
onWheel={onWheel}
|
onWheel={onWheel}
|
||||||
options={{ backgroundAlpha: 0 }}
|
options={{ backgroundAlpha: 0 }}
|
||||||
style={{ cursor: cssCursor }}
|
style={{ cursor: cssCursor }}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ function SelectionBar({ startBlocks, startSelectionCoords }: Props) {
|
||||||
const combinedBlocks = [...blocks, ...selectionLayerBlocks];
|
const combinedBlocks = [...blocks, ...selectionLayerBlocks];
|
||||||
const uniqueBlocks = Array.from(new Map(combinedBlocks.map((block) => [`${block.x},${block.y}`, block])).values());
|
const uniqueBlocks = Array.from(new Map(combinedBlocks.map((block) => [`${block.x},${block.y}`, block])).values());
|
||||||
|
|
||||||
setBlocks(uniqueBlocks);
|
setBlocks(uniqueBlocks.filter((b) => b.name !== "air"));
|
||||||
setSelectionLayerBlocks([]);
|
setSelectionLayerBlocks([]);
|
||||||
|
|
||||||
addHistory(
|
addHistory(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue