Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix: rotate the text element when binding to a rotated container (#6477)

siddhant851b9b7aecb9
diff --git a/src/components/App.tsx b/src/components/App.tsx
index 20def468aa..413a130d86 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -2744,6 +2744,7 @@ class App extends React.Component<AppProps, AppState> {
containerId: shouldBindToContainer ? container?.id : undefined,
groupIds: container?.groupIds ?? [],
lineHeight,
+ angle: container?.angle ?? 0,
});
if (!existingTextElement && shouldBindToContainer && container) {
diff --git a/src/element/textWysiwyg.test.tsx b/src/element/textWysiwyg.test.tsx
index 71c75c5a06..f3c75db8bb 100644
--- a/src/element/textWysiwyg.test.tsx
+++ b/src/element/textWysiwyg.test.tsx
@@ -526,6 +526,36 @@ describe("textWysiwyg", () => {
]);
});
+ it("should set the text element angle to same as container angle when binding to rotated container", async () => {
+ const rectangle = API.createElement({
+ type: "rectangle",
+ width: 90,
+ height: 75,
+ angle: 45,
+ });
+ h.elements = [rectangle];
+ mouse.doubleClickAt(rectangle.x + 10, rectangle.y + 10);
+ const text = h.elements[1] as ExcalidrawTextElementWithContainer;
+ expect(text.type).toBe("text");
+ expect(text.containerId).toBe(rectangle.id);
+ expect(rectangle.boundElements).toStrictEqual([
+ { id: text.id, type: "text" },
+ ]);
+ expect(text.angle).toBe(rectangle.angle);
+ mouse.down();
+ const editor = document.querySelector(
+ ".excalidraw-textEditorContainer > textarea",
+ ) as HTMLTextAreaElement;
+
+ fireEvent.change(editor, { target: { value: "Hello World!" } });
+
+ await new Promise((r) => setTimeout(r, 0));
+ editor.blur();
+ expect(rectangle.boundElements).toStrictEqual([
+ { id: text.id, type: "text" },
+ ]);
+ });
+
it("should compute the container height correctly and not throw error when height is updated while editing the text", async () => {
const diamond = API.createElement({
type: "diamond",