mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
respect initial type when switching between linears
This commit is contained in:
parent
63dd599089
commit
f99fe54797
2 changed files with 42 additions and 4 deletions
|
@ -44,7 +44,6 @@ import type {
|
|||
ExcalidrawIframeElement,
|
||||
ElementsMap,
|
||||
ExcalidrawArrowElement,
|
||||
FixedSegment,
|
||||
ExcalidrawElbowArrowElement,
|
||||
} from "./types";
|
||||
|
||||
|
@ -478,7 +477,7 @@ export const newArrowElement = <T extends boolean>(
|
|||
endArrowhead?: Arrowhead | null;
|
||||
points?: ExcalidrawArrowElement["points"];
|
||||
elbowed?: T;
|
||||
fixedSegments?: FixedSegment[] | null;
|
||||
fixedSegments?: ExcalidrawElbowArrowElement["fixedSegments"] | null;
|
||||
} & ElementConstructorOpts,
|
||||
): T extends true
|
||||
? NonDeleted<ExcalidrawElbowArrowElement>
|
||||
|
|
|
@ -508,9 +508,48 @@ export const switchShapes = (
|
|||
if (nextType && isConvertibleLinearType(nextType)) {
|
||||
const convertedElements: Record<string, ExcalidrawElement> = {};
|
||||
for (const element of selectedLinearSwitchableElements) {
|
||||
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 = [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue