Skip to content

Commit

Permalink
fix: rotate the text element when binding to a rotated container (exc…
Browse files Browse the repository at this point in the history
…alidraw#6477)

* Updated logic to update the bound child angle from the parent

* update angle when generating text element

* add test

* remove

* fix

---------

Co-authored-by: Aakansha Doshi <[email protected]>
  • Loading branch information
siddhant1 and ad1992 authored Apr 20, 2023
1 parent 5ddb28d commit 851b9b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions src/element/textWysiwyg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 851b9b7

Please sign in to comment.