Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
555bf6338f | ||
|
0bef3945f6 |
@ -933,10 +933,32 @@ describe("textWysiwyg", () => {
|
|||||||
|
|
||||||
await new Promise((cb) => setTimeout(cb, 0));
|
await new Promise((cb) => setTimeout(cb, 0));
|
||||||
editor.blur();
|
editor.blur();
|
||||||
expect(rectangle.width).toBe(110);
|
expect(rectangle.width).toBe(100);
|
||||||
expect(rectangle.height).toBe(210);
|
expect(rectangle.height).toBe(210);
|
||||||
const textElement = h.elements[1] as ExcalidrawTextElement;
|
const textElement = h.elements[1] as ExcalidrawTextElement;
|
||||||
expect(textElement.text).toBe(wrappedText);
|
expect(textElement.text).toMatchInlineSnapshot(
|
||||||
|
`
|
||||||
|
"Wikipedi
|
||||||
|
a is
|
||||||
|
hosted
|
||||||
|
by the
|
||||||
|
Wikimedi
|
||||||
|
a
|
||||||
|
Foundati
|
||||||
|
on, a
|
||||||
|
non-prof
|
||||||
|
it
|
||||||
|
organiza
|
||||||
|
tion
|
||||||
|
that
|
||||||
|
also
|
||||||
|
hosts a
|
||||||
|
range of
|
||||||
|
other
|
||||||
|
projects
|
||||||
|
."
|
||||||
|
`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -290,14 +290,21 @@ export const textWysiwyg = ({
|
|||||||
fontSize: app.state.currentItemFontSize,
|
fontSize: app.state.currentItemFontSize,
|
||||||
fontFamily: app.state.currentItemFontFamily,
|
fontFamily: app.state.currentItemFontFamily,
|
||||||
});
|
});
|
||||||
const wrappedText = container
|
|
||||||
? wrapText(data, font, getMaxContainerWidth(container))
|
|
||||||
: data;
|
|
||||||
|
|
||||||
const dimensions = measureText(wrappedText, font);
|
if (data) {
|
||||||
editable.style.height = `${dimensions.height}px`;
|
const text = editable.value;
|
||||||
|
const start = Math.min(editable.selectionStart, editable.selectionEnd);
|
||||||
onChange(wrappedText);
|
const end = Math.max(editable.selectionStart, editable.selectionEnd);
|
||||||
|
const newText = `${text.substring(0, start)}${data}${text.substring(
|
||||||
|
end,
|
||||||
|
)}`;
|
||||||
|
const wrappedText = container
|
||||||
|
? wrapText(newText, font, getMaxContainerWidth(container!))
|
||||||
|
: newText;
|
||||||
|
const dimensions = measureText(wrappedText, font);
|
||||||
|
editable.style.height = `${dimensions.height}px`;
|
||||||
|
onChange(newText);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
editable.oninput = () => {
|
editable.oninput = () => {
|
||||||
const updatedTextElement = Scene.getScene(element)?.getElement(
|
const updatedTextElement = Scene.getScene(element)?.getElement(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user