fix: Direct binding manipulation

This commit is contained in:
Mark Tolmacs
2025-08-21 14:46:02 +02:00
parent a2cd3f0e77
commit 42acd426a3
2 changed files with 23 additions and 30 deletions

View File

@@ -7,6 +7,7 @@ import {
getFontString, getFontString,
} from "@excalidraw/common"; } from "@excalidraw/common";
import { import {
bindOrUnbindLinearElement,
getOriginalContainerHeightFromCache, getOriginalContainerHeightFromCache,
resetOriginalContainerCache, resetOriginalContainerCache,
updateOriginalContainerCache, updateOriginalContainerCache,
@@ -36,6 +37,7 @@ import { newElement } from "@excalidraw/element";
import { CaptureUpdateAction } from "@excalidraw/element"; import { CaptureUpdateAction } from "@excalidraw/element";
import type { import type {
ExcalidrawBindableElement,
ExcalidrawElement, ExcalidrawElement,
ExcalidrawLinearElement, ExcalidrawLinearElement,
ExcalidrawTextContainer, ExcalidrawTextContainer,
@@ -270,7 +272,7 @@ export const actionWrapTextInContainer = register({
), ),
groupIds: textElement.groupIds, groupIds: textElement.groupIds,
frameId: textElement.frameId, frameId: textElement.frameId,
}); }) as ExcalidrawBindableElement;
// update bindings // update bindings
if (textElement.boundElements?.length) { if (textElement.boundElements?.length) {
@@ -281,26 +283,14 @@ export const actionWrapTextInContainer = register({
linearElementIds.includes(ele.id), linearElementIds.includes(ele.id),
) as ExcalidrawLinearElement[]; ) as ExcalidrawLinearElement[];
linearElements.forEach((ele) => { linearElements.forEach((ele) => {
let startBinding = ele.startBinding; bindOrUnbindLinearElement(
let endBinding = ele.endBinding; ele,
ele.startBinding?.elementId === textElement.id
if (startBinding?.elementId === textElement.id) { ? container
startBinding = { : "keep",
...startBinding, ele.endBinding?.elementId === textElement.id ? container : "keep",
elementId: container.id, app.scene,
}; );
}
if (endBinding?.elementId === textElement.id) {
endBinding = { ...endBinding, elementId: container.id };
}
if (startBinding || endBinding) {
app.scene.mutateElement(ele, {
startBinding,
endBinding,
});
}
}); });
} }

View File

@@ -1,6 +1,9 @@
import { KEYS, updateActiveTool } from "@excalidraw/common"; import { KEYS, updateActiveTool } from "@excalidraw/common";
import { getNonDeletedElements } from "@excalidraw/element"; import {
bindOrUnbindLinearElement,
getNonDeletedElements,
} from "@excalidraw/element";
import { fixBindingsAfterDeletion } from "@excalidraw/element"; import { fixBindingsAfterDeletion } from "@excalidraw/element";
import { LinearElementEditor } from "@excalidraw/element"; import { LinearElementEditor } from "@excalidraw/element";
import { newElementWith } from "@excalidraw/element"; import { newElementWith } from "@excalidraw/element";
@@ -92,14 +95,14 @@ const deleteSelectedElements = (
el.boundElements.forEach((candidate) => { el.boundElements.forEach((candidate) => {
const bound = app.scene.getNonDeletedElementsMap().get(candidate.id); const bound = app.scene.getNonDeletedElementsMap().get(candidate.id);
if (bound && isElbowArrow(bound)) { if (bound && isElbowArrow(bound)) {
app.scene.mutateElement(bound, { if (el.id === bound.startBinding?.elementId) {
startBinding: bindOrUnbindLinearElement(
el.id === bound.startBinding?.elementId bound,
? null el.id === bound.startBinding?.elementId ? null : "keep",
: bound.startBinding, el.id === bound.endBinding?.elementId ? null : "keep",
endBinding: app.scene,
el.id === bound.endBinding?.elementId ? null : bound.endBinding, );
}); }
} }
}); });
} }