fix: do not bind text to container using text tool when it has text already (#6694)
* fix: do not bind text to container using text tool when it has text already * Update src/element/textWysiwyg.test.tsx
This commit is contained in:
parent
0aa1e66486
commit
6d56634289
@ -3054,7 +3054,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
if (container && parentCenterPosition) {
|
if (container && parentCenterPosition) {
|
||||||
shouldBindToContainer = true;
|
const boundTextElementToContainer = getBoundTextElement(container);
|
||||||
|
if (!boundTextElementToContainer) {
|
||||||
|
shouldBindToContainer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let existingTextElement: NonDeleted<ExcalidrawTextElement> | null = null;
|
let existingTextElement: NonDeleted<ExcalidrawTextElement> | null = null;
|
||||||
|
|
||||||
|
@ -1459,5 +1459,54 @@ describe("textWysiwyg", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shouldn't bind to container if container has bound text not centered and text tool is used", async () => {
|
||||||
|
expect(h.elements.length).toBe(1);
|
||||||
|
|
||||||
|
Keyboard.keyPress(KEYS.ENTER);
|
||||||
|
|
||||||
|
expect(h.elements.length).toBe(2);
|
||||||
|
|
||||||
|
// Bind first text
|
||||||
|
let text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
||||||
|
expect(text.containerId).toBe(rectangle.id);
|
||||||
|
let editor = getTextEditor();
|
||||||
|
await new Promise((r) => setTimeout(r, 0));
|
||||||
|
updateTextEditor(editor, "Hello!");
|
||||||
|
expect(
|
||||||
|
(h.elements[1] as ExcalidrawTextElementWithContainer).verticalAlign,
|
||||||
|
).toBe(VERTICAL_ALIGN.MIDDLE);
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByTitle("Align bottom"));
|
||||||
|
await new Promise((r) => setTimeout(r, 0));
|
||||||
|
|
||||||
|
editor.blur();
|
||||||
|
|
||||||
|
expect(rectangle.boundElements).toStrictEqual([
|
||||||
|
{ id: text.id, type: "text" },
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
(h.elements[1] as ExcalidrawTextElementWithContainer).verticalAlign,
|
||||||
|
).toBe(VERTICAL_ALIGN.BOTTOM);
|
||||||
|
|
||||||
|
// Attempt to Bind 2nd text using text tool
|
||||||
|
UI.clickTool("text");
|
||||||
|
mouse.clickAt(
|
||||||
|
rectangle.x + rectangle.width / 2,
|
||||||
|
rectangle.y + rectangle.height / 2,
|
||||||
|
);
|
||||||
|
editor = getTextEditor();
|
||||||
|
await new Promise((r) => setTimeout(r, 0));
|
||||||
|
updateTextEditor(editor, "Excalidraw");
|
||||||
|
editor.blur();
|
||||||
|
|
||||||
|
expect(h.elements.length).toBe(3);
|
||||||
|
expect(rectangle.boundElements).toStrictEqual([
|
||||||
|
{ id: h.elements[1].id, type: "text" },
|
||||||
|
]);
|
||||||
|
text = h.elements[2] as ExcalidrawTextElementWithContainer;
|
||||||
|
expect(text.containerId).toBe(null);
|
||||||
|
expect(text.text).toBe("Excalidraw");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user