fix: Arrow angle reset

This commit is contained in:
Mark Tolmacs
2025-11-13 19:10:24 +01:00
parent 46d79a6ec6
commit f44198629c

View File

@@ -1,4 +1,4 @@
import { isFiniteNumber, pointFrom } from "@excalidraw/math"; import { isFiniteNumber, pointFrom, pointRotateRads } from "@excalidraw/math";
import { import {
DEFAULT_FONT_FAMILY, DEFAULT_FONT_FAMILY,
@@ -20,6 +20,7 @@ import {
} from "@excalidraw/common"; } from "@excalidraw/common";
import { import {
calculateFixedPointForNonElbowArrowBinding, calculateFixedPointForNonElbowArrowBinding,
elementCenterPoint,
getNonDeletedElements, getNonDeletedElements,
isPointInElement, isPointInElement,
isValidPolygon, isValidPolygon,
@@ -392,17 +393,33 @@ export const restoreElement = (
...getSizeFromPoints(points), ...getSizeFromPoints(points),
}); });
case "arrow": { case "arrow": {
const { startArrowhead = null, endArrowhead = "arrow" } = element; const {
let x: number | undefined = element.x; startArrowhead = null,
let y: number | undefined = element.y; endArrowhead = "arrow",
angle = 0,
} = element;
const x: number | undefined = element.x;
const y: number | undefined = element.y;
let points: readonly LocalPoint[] | undefined = // migrate old arrow model to new one let points: readonly LocalPoint[] | undefined = // migrate old arrow model to new one
!Array.isArray(element.points) || element.points.length < 2 !Array.isArray(element.points) || element.points.length < 2
? [pointFrom(0, 0), pointFrom(element.width, element.height)] ? [pointFrom(0, 0), pointFrom(element.width, element.height)]
: element.points; : element.points;
if (points[0][0] !== 0 || points[0][1] !== 0) { if (angle !== 0) {
({ points, x, y } = points = LinearElementEditor.getPointsGlobalCoordinates(
LinearElementEditor.getNormalizeElementPointsAndCoords(element)); element,
elementsMap,
).map((point) =>
LinearElementEditor.pointFromAbsoluteCoords(
element as ExcalidrawArrowElement,
pointRotateRads(
point,
elementCenterPoint(element, elementsMap),
angle,
),
elementsMap,
),
);
} }
const base = { const base = {
@@ -426,10 +443,11 @@ export const restoreElement = (
y, y,
elbowed: (element as ExcalidrawArrowElement).elbowed, elbowed: (element as ExcalidrawArrowElement).elbowed,
...getSizeFromPoints(points), ...getSizeFromPoints(points),
} as const; angle: 0 as Radians,
};
// TODO: Separate arrow from linear element // TODO: Separate arrow from linear element
return isElbowArrow(element) const restoredElement = isElbowArrow(element)
? restoreElementWithProperties(element as ExcalidrawElbowArrowElement, { ? restoreElementWithProperties(element as ExcalidrawElbowArrowElement, {
...base, ...base,
elbowed: true, elbowed: true,
@@ -441,6 +459,13 @@ export const restoreElement = (
endIsSpecial: element.endIsSpecial, endIsSpecial: element.endIsSpecial,
}) })
: restoreElementWithProperties(element as ExcalidrawArrowElement, base); : restoreElementWithProperties(element as ExcalidrawArrowElement, base);
return {
...restoredElement,
...LinearElementEditor.getNormalizeElementPointsAndCoords(
restoredElement,
),
};
} }
// generic elements // generic elements