|
@@ -11,7 +11,7 @@ import {
|
|
isBoundToContainer,
|
|
isBoundToContainer,
|
|
isTextElement,
|
|
isTextElement,
|
|
} from "./typeChecks";
|
|
} from "./typeChecks";
|
|
-import { CLASSES, isSafari, VERTICAL_ALIGN } from "../constants";
|
|
|
|
|
|
+import { CLASSES, isSafari } from "../constants";
|
|
import {
|
|
import {
|
|
ExcalidrawElement,
|
|
ExcalidrawElement,
|
|
ExcalidrawLinearElement,
|
|
ExcalidrawLinearElement,
|
|
@@ -23,7 +23,6 @@ import { AppState } from "../types";
|
|
import { mutateElement } from "./mutateElement";
|
|
import { mutateElement } from "./mutateElement";
|
|
import {
|
|
import {
|
|
getBoundTextElementId,
|
|
getBoundTextElementId,
|
|
- getContainerCoords,
|
|
|
|
getContainerDims,
|
|
getContainerDims,
|
|
getContainerElement,
|
|
getContainerElement,
|
|
getTextElementAngle,
|
|
getTextElementAngle,
|
|
@@ -35,6 +34,7 @@ import {
|
|
getBoundTextMaxWidth,
|
|
getBoundTextMaxWidth,
|
|
computeContainerDimensionForBoundText,
|
|
computeContainerDimensionForBoundText,
|
|
detectLineHeight,
|
|
detectLineHeight,
|
|
|
|
+ computeBoundTextPosition,
|
|
} from "./textElement";
|
|
} from "./textElement";
|
|
import {
|
|
import {
|
|
actionDecreaseFontSize,
|
|
actionDecreaseFontSize,
|
|
@@ -161,7 +161,7 @@ export const textWysiwyg = ({
|
|
let textElementWidth = updatedTextElement.width;
|
|
let textElementWidth = updatedTextElement.width;
|
|
// Set to element height by default since that's
|
|
// Set to element height by default since that's
|
|
// what is going to be used for unbounded text
|
|
// what is going to be used for unbounded text
|
|
- let textElementHeight = updatedTextElement.height;
|
|
|
|
|
|
+ const textElementHeight = updatedTextElement.height;
|
|
|
|
|
|
if (container && updatedTextElement.containerId) {
|
|
if (container && updatedTextElement.containerId) {
|
|
if (isArrowElement(container)) {
|
|
if (isArrowElement(container)) {
|
|
@@ -178,15 +178,6 @@ export const textWysiwyg = ({
|
|
editable,
|
|
editable,
|
|
);
|
|
);
|
|
const containerDims = getContainerDims(container);
|
|
const containerDims = getContainerDims(container);
|
|
- // using editor.style.height to get the accurate height of text editor
|
|
|
|
- const editorHeight = Number(editable.style.height.slice(0, -2));
|
|
|
|
- if (editorHeight > 0) {
|
|
|
|
- textElementHeight = editorHeight;
|
|
|
|
- }
|
|
|
|
- if (propertiesUpdated) {
|
|
|
|
- // update height of the editor after properties updated
|
|
|
|
- textElementHeight = updatedTextElement.height;
|
|
|
|
- }
|
|
|
|
|
|
|
|
let originalContainerData;
|
|
let originalContainerData;
|
|
if (propertiesUpdated) {
|
|
if (propertiesUpdated) {
|
|
@@ -231,22 +222,12 @@ export const textWysiwyg = ({
|
|
container.type,
|
|
container.type,
|
|
);
|
|
);
|
|
mutateElement(container, { height: targetContainerHeight });
|
|
mutateElement(container, { height: targetContainerHeight });
|
|
- }
|
|
|
|
- // Start pushing text upward until a diff of 30px (padding)
|
|
|
|
- // is reached
|
|
|
|
- else {
|
|
|
|
- const containerCoords = getContainerCoords(container);
|
|
|
|
-
|
|
|
|
- // vertically center align the text
|
|
|
|
- if (verticalAlign === VERTICAL_ALIGN.MIDDLE) {
|
|
|
|
- if (!isArrowElement(container)) {
|
|
|
|
- coordY =
|
|
|
|
- containerCoords.y + maxHeight / 2 - textElementHeight / 2;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (verticalAlign === VERTICAL_ALIGN.BOTTOM) {
|
|
|
|
- coordY = containerCoords.y + (maxHeight - textElementHeight);
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ const { y } = computeBoundTextPosition(
|
|
|
|
+ container,
|
|
|
|
+ updatedTextElement as ExcalidrawTextElementWithContainer,
|
|
|
|
+ );
|
|
|
|
+ coordY = y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const [viewportX, viewportY] = getViewportCoords(coordX, coordY);
|
|
const [viewportX, viewportY] = getViewportCoords(coordX, coordY);
|
|
@@ -392,26 +373,6 @@ export const textWysiwyg = ({
|
|
};
|
|
};
|
|
|
|
|
|
editable.oninput = () => {
|
|
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,
|
|
|
|
- getBoundTextMaxWidth(container!),
|
|
|
|
- );
|
|
|
|
- const { width, height } = measureText(
|
|
|
|
- wrappedText,
|
|
|
|
- font,
|
|
|
|
- updatedTextElement.lineHeight,
|
|
|
|
- getBoundTextMaxWidth(container!),
|
|
|
|
- );
|
|
|
|
- editable.style.width = `${width}px`;
|
|
|
|
- editable.style.height = `${height}px`;
|
|
|
|
- }
|
|
|
|
onChange(normalizeText(editable.value));
|
|
onChange(normalizeText(editable.value));
|
|
};
|
|
};
|
|
}
|
|
}
|