mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
test case + consistent text scaling
This commit is contained in:
parent
d783aaa236
commit
2ec50ca587
2 changed files with 125 additions and 5 deletions
|
@ -1503,11 +1503,15 @@ export const resizeMultipleElements = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTextElement(orig)) {
|
if (isTextElement(orig)) {
|
||||||
|
if (!shouldMaintainAspectRatio) {
|
||||||
const metrics = measureFontSizeFromWidth(orig, elementsMap, width);
|
const metrics = measureFontSizeFromWidth(orig, elementsMap, width);
|
||||||
if (!metrics) {
|
if (!metrics) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
update.fontSize = metrics.size;
|
update.fontSize = metrics.size;
|
||||||
|
} else {
|
||||||
|
update.fontSize = orig.fontSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const boundTextElement = originalElementsMap.get(
|
const boundTextElement = originalElementsMap.get(
|
||||||
|
@ -1515,7 +1519,7 @@ export const resizeMultipleElements = (
|
||||||
) as ExcalidrawTextElementWithContainer | undefined;
|
) as ExcalidrawTextElementWithContainer | undefined;
|
||||||
|
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
if (keepAspectRatio) {
|
if (keepAspectRatio && !shouldMaintainAspectRatio) {
|
||||||
const newFontSize = boundTextElement.fontSize * scale;
|
const newFontSize = boundTextElement.fontSize * scale;
|
||||||
if (newFontSize < MIN_FONT_SIZE) {
|
if (newFontSize < MIN_FONT_SIZE) {
|
||||||
return;
|
return;
|
||||||
|
|
116
packages/element/tests/groupResize.test.tsx
Normal file
116
packages/element/tests/groupResize.test.tsx
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
||||||
|
import { UI, Keyboard, Pointer } from "@excalidraw/excalidraw/tests/helpers/ui";
|
||||||
|
import { KEYS } from "@excalidraw/common";
|
||||||
|
import { unmountComponent } from "@excalidraw/excalidraw/tests/test-utils";
|
||||||
|
import { render } from "@excalidraw/excalidraw/tests/test-utils";
|
||||||
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
|
const { h } = window;
|
||||||
|
const mouse = new Pointer("mouse");
|
||||||
|
|
||||||
|
unmountComponent();
|
||||||
|
|
||||||
|
describe("group resize", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
h.elements = [];
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resizes group with locked aspect ratio using side handles", async () => {
|
||||||
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, 10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, -10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, -10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
const end = mouse.getPosition();
|
||||||
|
|
||||||
|
mouse.reset();
|
||||||
|
mouse.down();
|
||||||
|
mouse.restorePosition(...end);
|
||||||
|
mouse.up();
|
||||||
|
|
||||||
|
expect(h.elements.length).toBe(3);
|
||||||
|
for (const element of h.elements) {
|
||||||
|
expect(element.groupIds.length).toBe(0);
|
||||||
|
expect(h.state.selectedElementIds[element.id]).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
|
Keyboard.keyPress(KEYS.G);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const element of h.elements) {
|
||||||
|
expect(element.groupIds.length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mouse.select(h.elements[0]);
|
||||||
|
let originalWidth = h.elements[0].width;
|
||||||
|
let originalHeight = h.elements[0].height;
|
||||||
|
|
||||||
|
UI.resize(h.elements[0], 'se', [50, 50], { shift: true });
|
||||||
|
|
||||||
|
expect(h.elements[0].width).toBe(originalWidth + 50);
|
||||||
|
expect(h.elements[0].height).toBe(originalHeight + 50);
|
||||||
|
|
||||||
|
originalWidth = h.elements[0].width;
|
||||||
|
originalHeight = h.elements[0].height;
|
||||||
|
|
||||||
|
UI.resize(h.elements[0], "nw", [-50, -50], { shift: true });
|
||||||
|
|
||||||
|
expect(h.elements[0].width).toBe(originalWidth - 50);
|
||||||
|
expect(h.elements[0].height).toBe(originalHeight - 50);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resizes group with locked aspect ratio using corner handles", async () => {
|
||||||
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, 10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, -10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
mouse.down(10, -10);
|
||||||
|
mouse.up(10, 10);
|
||||||
|
const end = mouse.getPosition();
|
||||||
|
|
||||||
|
mouse.reset();
|
||||||
|
mouse.down();
|
||||||
|
mouse.restorePosition(...end);
|
||||||
|
mouse.up();
|
||||||
|
|
||||||
|
expect(h.elements.length).toBe(3);
|
||||||
|
for (const element of h.elements) {
|
||||||
|
expect(element.groupIds.length).toBe(0);
|
||||||
|
expect(h.state.selectedElementIds[element.id]).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
|
Keyboard.keyPress(KEYS.G);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const element of h.elements) {
|
||||||
|
expect(element.groupIds.length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mouse.select(h.elements[0]);
|
||||||
|
|
||||||
|
let originalWidth = h.elements[0].width;
|
||||||
|
let originalHeight = h.elements[0].height;
|
||||||
|
|
||||||
|
UI.resize(h.elements[0], "se", [50, 50], { shift: true });
|
||||||
|
|
||||||
|
|
||||||
|
expect(h.elements[0].width).toBe(originalWidth + 50);
|
||||||
|
expect(h.elements[0].height).toBe(originalHeight + 50);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue