diff --git a/packages/element/src/newElement.ts b/packages/element/src/newElement.ts index 53a2f05ae..2ce9f306c 100644 --- a/packages/element/src/newElement.ts +++ b/packages/element/src/newElement.ts @@ -44,7 +44,6 @@ import type { ExcalidrawIframeElement, ElementsMap, ExcalidrawArrowElement, - FixedSegment, ExcalidrawElbowArrowElement, } from "./types"; @@ -478,7 +477,7 @@ export const newArrowElement = ( endArrowhead?: Arrowhead | null; points?: ExcalidrawArrowElement["points"]; elbowed?: T; - fixedSegments?: FixedSegment[] | null; + fixedSegments?: ExcalidrawElbowArrowElement["fixedSegments"] | null; } & ElementConstructorOpts, ): T extends true ? NonDeleted diff --git a/packages/excalidraw/components/ShapeSwitch.tsx b/packages/excalidraw/components/ShapeSwitch.tsx index 1976e7a35..2c78d8b57 100644 --- a/packages/excalidraw/components/ShapeSwitch.tsx +++ b/packages/excalidraw/components/ShapeSwitch.tsx @@ -508,8 +508,47 @@ export const switchShapes = ( if (nextType && isConvertibleLinearType(nextType)) { const convertedElements: Record = {}; for (const element of selectedLinearSwitchableElements) { - const converted = convertElementType(element, nextType, app); - convertedElements[converted.id] = converted; + const { properties, initialType } = + editorJotaiStore.get(shapeSwitchLinearAtom)?.[element.id] || {}; + + // If the initial type is not elbow, and when we switch to elbow, + // the linear line might be "bent" and the points would likely be different. + // When we then switch to other non elbow types from this converted elbow, + // we still want to use the original points instead. + if ( + initialType && + properties && + isElbowArrow(element) && + initialType !== "elbowArrow" && + nextType !== "elbowArrow" + ) { + // first convert back to the original type + const originalType = convertElementType( + element, + initialType, + app, + ) as ExcalidrawLinearElement; + // then convert to the target type + const converted = convertElementType( + initialType === "line" + ? newLinearElement({ + ...originalType, + ...properties, + type: "line", + }) + : newArrowElement({ + ...originalType, + ...properties, + type: "arrow", + }), + nextType, + app, + ); + convertedElements[converted.id] = converted; + } else { + const converted = convertElementType(element, nextType, app); + convertedElements[converted.id] = converted; + } } const nextElements = [];