use commonBounds instead of boundingBox
This commit is contained in:
parent
b0ca8f8126
commit
2bca4c258d
@ -1,5 +1,5 @@
|
|||||||
import { updateBoundElements } from "./binding";
|
import { updateBoundElements } from "./binding";
|
||||||
import { BoundingBox, getCommonBoundingBox, getCommonBounds } from "./bounds";
|
import { Bounds, getCommonBounds } from "./bounds";
|
||||||
import { mutateElement } from "./mutateElement";
|
import { mutateElement } from "./mutateElement";
|
||||||
import { getPerfectElementSize } from "./sizeHelpers";
|
import { getPerfectElementSize } from "./sizeHelpers";
|
||||||
import { NonDeletedExcalidrawElement } from "./types";
|
import { NonDeletedExcalidrawElement } from "./types";
|
||||||
@ -41,9 +41,9 @@ export const dragSelectedElements = (
|
|||||||
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
const boundingBox = getCommonBoundingBox(Array.from(elementsToUpdate));
|
const commonBounds = getCommonBounds(Array.from(elementsToUpdate));
|
||||||
const adjustedOffset = calculateOffset(
|
const adjustedOffset = calculateOffset(
|
||||||
boundingBox,
|
commonBounds,
|
||||||
offset,
|
offset,
|
||||||
snapOffset,
|
snapOffset,
|
||||||
gridSize,
|
gridSize,
|
||||||
@ -78,18 +78,19 @@ export const dragSelectedElements = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const calculateOffset = (
|
const calculateOffset = (
|
||||||
boundingBox: BoundingBox,
|
commonBounds: Bounds,
|
||||||
dragOffset: { x: number; y: number },
|
dragOffset: { x: number; y: number },
|
||||||
snapOffset: { x: number; y: number },
|
snapOffset: { x: number; y: number },
|
||||||
gridSize: AppState["gridSize"],
|
gridSize: AppState["gridSize"],
|
||||||
): { x: number; y: number } => {
|
): { x: number; y: number } => {
|
||||||
let nextX = boundingBox.minX + dragOffset.x + snapOffset.x;
|
const [x, y] = commonBounds;
|
||||||
let nextY = boundingBox.minY + dragOffset.y + snapOffset.y;
|
let nextX = x + dragOffset.x + snapOffset.x;
|
||||||
|
let nextY = y + dragOffset.y + snapOffset.y;
|
||||||
|
|
||||||
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
||||||
const [nextGridX, nextGridY] = getGridPoint(
|
const [nextGridX, nextGridY] = getGridPoint(
|
||||||
boundingBox.minX + dragOffset.x,
|
x + dragOffset.x,
|
||||||
boundingBox.minY + dragOffset.y,
|
y + dragOffset.y,
|
||||||
gridSize,
|
gridSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -102,8 +103,8 @@ const calculateOffset = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
x: nextX - boundingBox.minX,
|
x: nextX - x,
|
||||||
y: nextY - boundingBox.minY,
|
y: nextY - y,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user