fix(editor): resizing text by a corner follows the cursor on the axis it grows most (#12262)

Text scaled by the height alone, so a corner dragged sideways didn't follow
the cursor; it now scales as resizing keeping the aspect ratio does (which
text always does), by the axis that grows most.

Claude Opus 5.5 (1M), xhigh effort
This commit is contained in:
David Luzar
2026-10-11 16:48:34 +02:00
committed by GitHub
parent ef53e5417b
commit 2df993fb39
2 changed files with 21 additions and 0 deletions
+9
View File
@@ -325,6 +325,15 @@ export const resizeSingleTextElement = (
) => {
const elementsMap = scene.getNonDeletedElementsMap();
// a corner follows the axis it grows most, as keeping the aspect ratio
// does (which text always does)
if (transformHandleType.length === 2) {
nextHeight = Math.max(
nextHeight,
(nextWidth / origElement.width) * origElement.height,
);
}
const metricsWidth = element.width * (nextHeight / element.height);
const metrics = measureFontSizeFromWidth(element, elementsMap, metricsWidth);
+12
View File
@@ -734,6 +734,18 @@ describe("text element", () => {
expect(text.fontSize).toBeCloseTo(fontSize * scale);
});
it("resizes by a corner following the axis it grows most", async () => {
const text = UI.createElement("text");
await UI.editText(text, "hello\nworld");
const { width, height, fontSize } = text;
const scale = 60 / width + 1;
UI.resize(text, "se", [60, 5]);
expect(text.width).toBeCloseTo(width * scale);
expect(text.height).toBeCloseTo(height * scale);
expect(text.fontSize).toBeCloseTo(fontSize * scale);
});
// TODO enable this test after adding single text element flipping
it.skip("flips while resizing", async () => {
const text = UI.createElement("text");