fix: #8475 Arrow updated on both sides (#8593)

This commit is contained in:
Ritobroto Kalita 2025-03-04 21:54:39 +05:30 committed by GitHub
parent d21c6a1bc6
commit c5d3bb0b6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 77 additions and 38 deletions

View file

@ -17,7 +17,11 @@ import type {
} from "./types";
import type { Bounds } from "./bounds";
import { getCenterForBounds } from "./bounds";
import {
getCenterForBounds,
getElementBounds,
doBoundsIntersect,
} from "./bounds";
import type { AppState } from "../types";
import { isPointOnShape } from "@excalidraw/utils/collision";
import {
@ -743,6 +747,21 @@ export const updateBoundElements = (
return;
}
// Check for intersections before updating bound elements incase connected elements overlap
const startBindingElement = element.startBinding
? elementsMap.get(element.startBinding.elementId)
: null;
const endBindingElement = element.endBinding
? elementsMap.get(element.endBinding.elementId)
: null;
let startBounds: Bounds | null = null;
let endBounds: Bounds | null = null;
if (startBindingElement && endBindingElement) {
startBounds = getElementBounds(startBindingElement, elementsMap);
endBounds = getElementBounds(endBindingElement, elementsMap);
}
const bindings = {
startBinding: maybeCalculateNewGapWhenScaling(
changedElement,
@ -770,7 +789,12 @@ export const updateBoundElements = (
bindableElement &&
isBindableElement(bindableElement) &&
(bindingProp === "startBinding" || bindingProp === "endBinding") &&
changedElement.id === element[bindingProp]?.elementId
(changedElement.id === element[bindingProp]?.elementId ||
(changedElement.id ===
element[
bindingProp === "startBinding" ? "endBinding" : "startBinding"
]?.elementId &&
!doBoundsIntersect(startBounds, endBounds)))
) {
const point = updateBoundPoint(
element,

View file

@ -1013,3 +1013,17 @@ export const getCenterForBounds = (bounds: Bounds): GlobalPoint =>
bounds[0] + (bounds[2] - bounds[0]) / 2,
bounds[1] + (bounds[3] - bounds[1]) / 2,
);
export const doBoundsIntersect = (
bounds1: Bounds | null,
bounds2: Bounds | null,
): boolean => {
if (bounds1 == null || bounds2 == null) {
return false;
}
const [minX1, minY1, maxX1, maxY1] = bounds1;
const [minX2, minY2, maxX2, maxY2] = bounds2;
return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
};

View file

@ -219,7 +219,9 @@ export class LinearElementEditor {
});
}
/** @returns whether point was dragged */
/**
* @returns whether point was dragged
*/
static handlePointDragging(
event: PointerEvent,
app: AppClassProperties,