fix: bound text coordinates not being updated

This commit is contained in:
Alex Kim 2023-05-04 20:13:54 +05:00
parent f4d21c26f5
commit c8fa32780c
No known key found for this signature in database
GPG key ID: CEE74CFA44D238D7

View file

@ -51,6 +51,7 @@ import {
measureText, measureText,
getMaxContainerHeight, getMaxContainerHeight,
} from "./textElement"; } from "./textElement";
import { LinearElementEditor } from "./linearElementEditor";
export const normalizeAngle = (angle: number): number => { export const normalizeAngle = (angle: number): number => {
if (angle < 0) { if (angle < 0) {
@ -634,12 +635,23 @@ export const resizeMultipleElements = (
// getCommonBoundingBox() uses getBoundTextElement() which returns null for // getCommonBoundingBox() uses getBoundTextElement() which returns null for
// original elements from pointerDownState, so we have to find and add these // original elements from pointerDownState, so we have to find and add these
// bound text elements manually // bound text elements manually. Additionally, the coordinates of bound text
const boundTextElements = targetElements // elements aren't always up to date.
.map(({ orig }) => getBoundTextElementId(orig)) const boundTextElements = targetElements.reduce((acc, { orig }) => {
.filter((id): id is string => typeof id === "string") if (!isLinearElement(orig)) {
.map((id) => pointerDownState.originalElements.get(id) ?? null) return acc;
.filter(isBoundToContainer); }
const textId = getBoundTextElementId(orig);
if (!textId) {
return acc;
}
const text = pointerDownState.originalElements.get(textId) ?? null;
if (!isBoundToContainer(text)) {
return acc;
}
const xy = LinearElementEditor.getBoundTextElementPosition(orig, text);
return [...acc, { ...text, ...xy }];
}, [] as ExcalidrawTextElementWithContainer[]);
const { minX, minY, maxX, maxY, midX, midY } = getCommonBoundingBox( const { minX, minY, maxX, maxY, midX, midY } = getCommonBoundingBox(
targetElements.map(({ orig }) => orig).concat(boundTextElements), targetElements.map(({ orig }) => orig).concat(boundTextElements),