Fix arrow label rotation bug

This commit is contained in:
Mark Tolmacs 2025-04-13 21:06:25 +02:00
parent af8d4e12be
commit 5a4c1fb6b5
2 changed files with 35 additions and 32 deletions

View file

@ -351,7 +351,10 @@ export const getTextElementAngle = (
textElement: ExcalidrawTextElement, textElement: ExcalidrawTextElement,
container: ExcalidrawTextContainer | null, container: ExcalidrawTextContainer | null,
) => { ) => {
if (!container || isArrowElement(container)) { if (isArrowElement(container)) {
return 0;
}
if (!container) {
return textElement.angle; return textElement.angle;
} }
return container.angle; return container.angle;

View file

@ -5352,37 +5352,37 @@ class App extends React.Component<AppProps, AppState> {
y: sceneY, y: sceneY,
}); });
const element = existingTextElement const element =
? existingTextElement existingTextElement ||
: newTextElement({ newTextElement({
x: parentCenterPosition x: parentCenterPosition ? parentCenterPosition.elementCenterX : sceneX,
? parentCenterPosition.elementCenterX y: parentCenterPosition ? parentCenterPosition.elementCenterY : sceneY,
: sceneX, strokeColor: this.state.currentItemStrokeColor,
y: parentCenterPosition backgroundColor: this.state.currentItemBackgroundColor,
? parentCenterPosition.elementCenterY fillStyle: this.state.currentItemFillStyle,
: sceneY, strokeWidth: this.state.currentItemStrokeWidth,
strokeColor: this.state.currentItemStrokeColor, strokeStyle: this.state.currentItemStrokeStyle,
backgroundColor: this.state.currentItemBackgroundColor, roughness: this.state.currentItemRoughness,
fillStyle: this.state.currentItemFillStyle, opacity: this.state.currentItemOpacity,
strokeWidth: this.state.currentItemStrokeWidth, text: "",
strokeStyle: this.state.currentItemStrokeStyle, fontSize,
roughness: this.state.currentItemRoughness, fontFamily,
opacity: this.state.currentItemOpacity, textAlign: parentCenterPosition
text: "", ? "center"
fontSize, : this.state.currentItemTextAlign,
fontFamily, verticalAlign: parentCenterPosition
textAlign: parentCenterPosition ? VERTICAL_ALIGN.MIDDLE
? "center" : DEFAULT_VERTICAL_ALIGN,
: this.state.currentItemTextAlign, containerId: shouldBindToContainer ? container?.id : undefined,
verticalAlign: parentCenterPosition groupIds: container?.groupIds ?? [],
? VERTICAL_ALIGN.MIDDLE lineHeight,
: DEFAULT_VERTICAL_ALIGN, angle: container
containerId: shouldBindToContainer ? container?.id : undefined, ? isArrowElement(container)
groupIds: container?.groupIds ?? [], ? (0 as Radians)
lineHeight, : container.angle
angle: container?.angle ?? (0 as Radians), : (0 as Radians),
frameId: topLayerFrame ? topLayerFrame.id : null, frameId: topLayerFrame ? topLayerFrame.id : null,
}); });
if (!existingTextElement && shouldBindToContainer && container) { if (!existingTextElement && shouldBindToContainer && container) {
mutateElement(container, { mutateElement(container, {