Compare commits

...

10 Commits

Author SHA1 Message Date
zsviczian
c1f8eca7de
Update textWysiwyg.tsx 2023-03-07 09:57:23 +01:00
zsviczian
340b9757c3
Update textWysiwyg.tsx 2023-03-07 09:54:50 +01:00
zsviczian
6035ebe95f added comment 2023-03-06 23:45:54 +01:00
zsviczian
1a877fa8c7 magicOffset only for Firefox and Safari 2023-03-06 23:45:11 +01:00
zsviczian
956228f4a1 moved offset to onEditableInput 2023-03-06 23:38:35 +01:00
zsviczian
cfb9f8d8c7 onInput 2023-03-06 22:24:00 +01:00
zsviczian
da06e8ad27 apply offset only if in container 2023-03-06 21:52:02 +01:00
zsviczian
27c7e75761 lint 2023-03-06 21:37:37 +01:00
zsviczian
2b8d69c65d lint 2023-03-06 21:35:23 +01:00
zsviczian
6d071a8a13 magicOffset 2023-03-06 21:28:48 +01:00

View File

@ -11,7 +11,7 @@ import {
isBoundToContainer,
isTextElement,
} from "./typeChecks";
import { CLASSES, isFirefox, isSafari, VERTICAL_ALIGN } from "../constants";
import { CLASSES, VERTICAL_ALIGN } from "../constants";
import {
ExcalidrawElement,
ExcalidrawLinearElement,
@ -270,12 +270,10 @@ export const textWysiwyg = ({
const lineHeight = updatedTextElement.containerId
? approxLineHeight
: updatedTextElement.height / lines.length;
if (!container) {
maxWidth = (appState.width - 8 - viewportX) / appState.zoom.value;
textElementWidth = Math.min(textElementWidth, maxWidth);
} else if (isFirefox || isSafari) {
// As firefox, Safari needs little higher dimensions on DOM
textElementWidth += 0.5;
}
// Make sure text editor height doesn't go beyond viewport
const editorMaxHeight =
@ -348,7 +346,32 @@ export const textWysiwyg = ({
overflowWrap: "break-word",
boxSizing: "content-box",
});
const magicOffset =
(excalidrawContainer
? parseFloat(getComputedStyle(excalidrawContainer).fontSize)
: 16) / 16;
const onEditableInput = () => {
const updatedTextElement = Scene.getScene(element)?.getElement(
id,
) as ExcalidrawTextElement;
const font = getFontString(updatedTextElement);
if (isBoundToContainer(element)) {
const container = getContainerElement(element);
const wrappedText = wrapText(
normalizeText(editable.value),
font,
getMaxContainerWidth(container!),
);
const { width, height } = measureText(wrappedText, font);
editable.style.width = `${width + magicOffset}px`;
editable.style.height = `${height}px`;
}
};
updateWysiwygStyle();
onEditableInput();
if (onChange) {
editable.onpaste = async (event) => {
@ -378,21 +401,7 @@ export const textWysiwyg = ({
};
editable.oninput = () => {
const updatedTextElement = Scene.getScene(element)?.getElement(
id,
) as ExcalidrawTextElement;
const font = getFontString(updatedTextElement);
if (isBoundToContainer(element)) {
const container = getContainerElement(element);
const wrappedText = wrapText(
normalizeText(editable.value),
font,
getMaxContainerWidth(container!),
);
const { width, height } = measureText(wrappedText, font);
editable.style.width = `${width}px`;
editable.style.height = `${height}px`;
}
onEditableInput();
onChange(normalizeText(editable.value));
};
}