resolved issue where rectangles were taking priority over normal items during lasso operations, this needs to be fixed in future

This commit is contained in:
stan
2025-10-01 20:58:25 +01:00
parent 5df41f9fd9
commit 128232081a
3 changed files with 31 additions and 12 deletions

View File

@@ -52,10 +52,15 @@ const dragItems = (
});
}
}
// Handle non-item references (rectangles, textboxes, connector anchors)
otherRefs.forEach((item) => {
if (item.type === 'RECTANGLE') {
// Skip rectangles if regular items are also being dragged
// This is because items use snap-to-grid logic, while rectangles move freely
// Moving them together would cause desynchronization
if (itemRefs.length > 0) return;
const rectangle = getItemByIdOrThrow(scene.rectangles, item.id).value;
const newFrom = CoordsUtils.add(rectangle.from, delta);
const newTo = CoordsUtils.add(rectangle.to, delta);

View File

@@ -18,13 +18,19 @@ const getItemsInFreehandBounds = (
}
});
// Check all rectangles (check center point)
// Check all rectangles - they must be FULLY enclosed (all 4 corners inside)
scene.rectangles.forEach((rectangle: any) => {
const centerX = (rectangle.from.x + rectangle.to.x) / 2;
const centerY = (rectangle.from.y + rectangle.to.y) / 2;
const center = { x: centerX, y: centerY };
const corners = [
rectangle.from,
{ x: rectangle.to.x, y: rectangle.from.y },
rectangle.to,
{ x: rectangle.from.x, y: rectangle.to.y }
];
if (isPointInPolygon(center, pathTiles)) {
// Rectangle is only selected if ALL corners are inside the polygon
const allCornersInside = corners.every(corner => isPointInPolygon(corner, pathTiles));
if (allCornersInside) {
items.push({ type: 'RECTANGLE', id: rectangle.id });
}
});

View File

@@ -17,13 +17,21 @@ const getItemsInBounds = (
}
});
// Check all rectangles
// Check all rectangles - they must be FULLY enclosed (all 4 corners inside)
scene.rectangles.forEach((rectangle: any) => {
// Check if rectangle's center or any corner is within bounds
if (
isWithinBounds(rectangle.from, [startTile, endTile]) ||
isWithinBounds(rectangle.to, [startTile, endTile])
) {
const corners = [
rectangle.from,
{ x: rectangle.to.x, y: rectangle.from.y },
rectangle.to,
{ x: rectangle.from.x, y: rectangle.to.y }
];
// Rectangle is only selected if ALL corners are inside the bounds
const allCornersInside = corners.every(corner =>
isWithinBounds(corner, [startTile, endTile])
);
if (allCornersInside) {
items.push({ type: 'RECTANGLE', id: rectangle.id });
}
});