mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-10-14 03:30:23 +02:00
fix(eraser): Remove binding from the other element
This commit is contained in:
@@ -243,6 +243,7 @@ import {
|
|||||||
getBindingStrategyForDraggingBindingElementEndpoints,
|
getBindingStrategyForDraggingBindingElementEndpoints,
|
||||||
getStartGlobalEndLocalPointsForSimpleArrowBinding,
|
getStartGlobalEndLocalPointsForSimpleArrowBinding,
|
||||||
snapToCenter,
|
snapToCenter,
|
||||||
|
mutateElement,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
|
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
|
||||||
@@ -10507,6 +10508,67 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
private eraseElements = () => {
|
private eraseElements = () => {
|
||||||
let didChange = false;
|
let didChange = false;
|
||||||
|
|
||||||
|
// Binding is double accounted on both elements and if one of them is
|
||||||
|
// deleted, the binding should be removed
|
||||||
|
this.elementsPendingErasure.forEach((id) => {
|
||||||
|
const element = this.scene.getElement(id);
|
||||||
|
if (isBindingElement(element)) {
|
||||||
|
if (element.startBinding) {
|
||||||
|
const bindable = this.scene.getElement(
|
||||||
|
element.startBinding.elementId,
|
||||||
|
)!;
|
||||||
|
// NOTE: We use the raw mutateElement() because we don't want history
|
||||||
|
// entries or multiplayer updates
|
||||||
|
mutateElement(bindable, this.scene.getElementsMapIncludingDeleted(), {
|
||||||
|
boundElements: bindable.boundElements!.filter(
|
||||||
|
(e) => e.id !== element.id,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (element.endBinding) {
|
||||||
|
const bindable = this.scene.getElement(element.endBinding.elementId)!;
|
||||||
|
// NOTE: We use the raw mutateElement() because we don't want history
|
||||||
|
// entries or multiplayer updates
|
||||||
|
mutateElement(bindable, this.scene.getElementsMapIncludingDeleted(), {
|
||||||
|
boundElements: bindable.boundElements!.filter(
|
||||||
|
(e) => e.id !== element.id,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (isBindableElement(element)) {
|
||||||
|
element.boundElements?.forEach((boundElement) => {
|
||||||
|
if (boundElement.type === "arrow") {
|
||||||
|
const arrow = this.scene.getElement(
|
||||||
|
boundElement.id,
|
||||||
|
) as ExcalidrawArrowElement;
|
||||||
|
if (arrow?.startBinding?.elementId === element.id) {
|
||||||
|
// NOTE: We use the raw mutateElement() because we don't want history
|
||||||
|
// entries or multiplayer updates
|
||||||
|
mutateElement(
|
||||||
|
arrow,
|
||||||
|
this.scene.getElementsMapIncludingDeleted(),
|
||||||
|
{
|
||||||
|
startBinding: null,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (arrow?.endBinding?.elementId === element.id) {
|
||||||
|
// NOTE: We use the raw mutateElement() because we don't want history
|
||||||
|
// entries or multiplayer updates
|
||||||
|
mutateElement(
|
||||||
|
arrow,
|
||||||
|
this.scene.getElementsMapIncludingDeleted(),
|
||||||
|
{
|
||||||
|
endBinding: null,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const elements = this.scene.getElementsIncludingDeleted().map((ele) => {
|
const elements = this.scene.getElementsIncludingDeleted().map((ele) => {
|
||||||
if (
|
if (
|
||||||
this.elementsPendingErasure.has(ele.id) ||
|
this.elementsPendingErasure.has(ele.id) ||
|
||||||
|
Reference in New Issue
Block a user