mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: compute dimensions of container correctly when text pasted on container (#5845)
* fix: compute dimensions of container correctly when text pasted on container * add test * remove only
This commit is contained in:
parent
e1c5c706c6
commit
e201e79cd0
4 changed files with 71 additions and 7 deletions
|
@ -10,11 +10,13 @@ import { BOUND_TEXT_PADDING, FONT_FAMILY } from "../constants";
|
|||
import {
|
||||
ExcalidrawTextElement,
|
||||
ExcalidrawTextElementWithContainer,
|
||||
FontString,
|
||||
} from "./types";
|
||||
import * as textElementUtils from "./textElement";
|
||||
import { API } from "../tests/helpers/api";
|
||||
import { mutateElement } from "./mutateElement";
|
||||
import { resize } from "../tests/utils";
|
||||
import { getMaxContainerWidth } from "./newElement";
|
||||
// Unmount ReactDOM from root
|
||||
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
||||
|
||||
|
@ -876,5 +878,44 @@ describe("textWysiwyg", () => {
|
|||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("should compute the dimensions correctly when text pasted", async () => {
|
||||
Keyboard.keyPress(KEYS.ENTER);
|
||||
const editor = document.querySelector(
|
||||
".excalidraw-textEditorContainer > textarea",
|
||||
) as HTMLTextAreaElement;
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
const font = "20px Cascadia, width: Segoe UI Emoji" as FontString;
|
||||
|
||||
const wrappedText = textElementUtils.wrapText(
|
||||
"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.",
|
||||
font,
|
||||
getMaxContainerWidth(rectangle),
|
||||
);
|
||||
|
||||
jest
|
||||
.spyOn(textElementUtils, "measureText")
|
||||
.mockImplementation((text, font, maxWidth) => {
|
||||
if (text === wrappedText) {
|
||||
return { width: rectangle.width, height: 200, baseline: 30 };
|
||||
}
|
||||
return { width: 0, height: 0, baseline: 0 };
|
||||
});
|
||||
|
||||
//@ts-ignore
|
||||
editor.onpaste({
|
||||
preventDefault: () => {},
|
||||
//@ts-ignore
|
||||
clipboardData: {
|
||||
getData: () =>
|
||||
"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.",
|
||||
},
|
||||
});
|
||||
|
||||
await new Promise((cb) => setTimeout(cb, 0));
|
||||
editor.blur();
|
||||
expect(rectangle.width).toBe(110);
|
||||
expect(rectangle.height).toBe(210);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue