mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-13 12:29:58 +02:00
fix: Direct binding manipulation
This commit is contained in:
@@ -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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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,
|
);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user