mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: z-index change by one causes app to freeze (#8314)
This commit is contained in:
parent
261304c1a4
commit
d5f4ee7b3f
2 changed files with 36 additions and 14 deletions
|
@ -246,6 +246,20 @@ describe("z-index manipulation", () => {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// elements should not duplicate
|
||||||
|
assertZindex({
|
||||||
|
elements: [
|
||||||
|
{ id: "A", containerId: "C" },
|
||||||
|
{ id: "B" },
|
||||||
|
{ id: "C", isSelected: true },
|
||||||
|
],
|
||||||
|
operations: [
|
||||||
|
[actionSendBackward, ["A", "C", "B"]],
|
||||||
|
// noop
|
||||||
|
[actionSendBackward, ["A", "C", "B"]],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
// grouped elements should be atomic
|
// grouped elements should be atomic
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -80,29 +80,37 @@ const getTargetIndexAccountingForBinding = (
|
||||||
direction: "left" | "right",
|
direction: "left" | "right",
|
||||||
) => {
|
) => {
|
||||||
if ("containerId" in nextElement && nextElement.containerId) {
|
if ("containerId" in nextElement && nextElement.containerId) {
|
||||||
if (direction === "left") {
|
const containerElement = Scene.getScene(nextElement)!.getElement(
|
||||||
const containerElement = Scene.getScene(nextElement)!.getElement(
|
nextElement.containerId,
|
||||||
nextElement.containerId,
|
);
|
||||||
);
|
if (containerElement) {
|
||||||
if (containerElement) {
|
return direction === "left"
|
||||||
return elements.indexOf(containerElement);
|
? Math.min(
|
||||||
}
|
elements.indexOf(containerElement),
|
||||||
} else {
|
elements.indexOf(nextElement),
|
||||||
return elements.indexOf(nextElement);
|
)
|
||||||
|
: Math.max(
|
||||||
|
elements.indexOf(containerElement),
|
||||||
|
elements.indexOf(nextElement),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const boundElementId = nextElement.boundElements?.find(
|
const boundElementId = nextElement.boundElements?.find(
|
||||||
(binding) => binding.type !== "arrow",
|
(binding) => binding.type !== "arrow",
|
||||||
)?.id;
|
)?.id;
|
||||||
if (boundElementId) {
|
if (boundElementId) {
|
||||||
if (direction === "left") {
|
|
||||||
return elements.indexOf(nextElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
const boundTextElement =
|
const boundTextElement =
|
||||||
Scene.getScene(nextElement)!.getElement(boundElementId);
|
Scene.getScene(nextElement)!.getElement(boundElementId);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
return elements.indexOf(boundTextElement);
|
return direction === "left"
|
||||||
|
? Math.min(
|
||||||
|
elements.indexOf(boundTextElement),
|
||||||
|
elements.indexOf(nextElement),
|
||||||
|
)
|
||||||
|
: Math.max(
|
||||||
|
elements.indexOf(boundTextElement),
|
||||||
|
elements.indexOf(nextElement),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue