mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-10-19 16:15:56 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user