Virtual whiteboard for sketching hand-drawn like diagrams
fix(editor): resizing text by a corner follows the cursor on the axis it grows most (#12262)
David Luzar2df993fb397d
diff --git a/packages/element/src/resizeElements.ts b/packages/element/src/resizeElements.tsindex c252961bd2..5e0e56b2cb 100644--- a/packages/element/src/resizeElements.ts+++ b/packages/element/src/resizeElements.ts@@ -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);diff --git a/packages/element/tests/resize.test.tsx b/packages/element/tests/resize.test.tsxindex 9efe69a181..772a8f7c0d 100644--- a/packages/element/tests/resize.test.tsx+++ b/packages/element/tests/resize.test.tsx@@ -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 flippingit.skip("flips while resizing", async () => {const text = UI.createElement("text");