feat: wrap texts from stats panel (#9552)

This commit is contained in:
Ryan Di
2025-06-14 21:05:24 +10:00
committed by GitHub
parent 84e96e9393
commit 93c92d13e9
3 changed files with 74 additions and 200 deletions

View File

@@ -401,11 +401,23 @@ describe("stats for a non-generic element", () => {
UI.updateInput(input, "36");
expect(text.fontSize).toBe(36);
// cannot change width or height
const width = UI.queryStatsProperty("W")?.querySelector(".drag-input");
expect(width).toBeUndefined();
const height = UI.queryStatsProperty("H")?.querySelector(".drag-input");
expect(height).toBeUndefined();
// can change width or height
const width = UI.queryStatsProperty("W")?.querySelector(
".drag-input",
) as HTMLInputElement;
expect(width).toBeDefined();
const height = UI.queryStatsProperty("H")?.querySelector(
".drag-input",
) as HTMLInputElement;
expect(height).toBeDefined();
const textHeightBeforeWrapping = text.height;
const textBeforeWrapping = text.text;
const originalTextBeforeWrapping = textBeforeWrapping;
UI.updateInput(width, "30");
expect(text.height).toBeGreaterThan(textHeightBeforeWrapping);
expect(text.text).not.toBe(textBeforeWrapping);
expect(text.originalText).toBe(originalTextBeforeWrapping);
// min font size is 4
UI.updateInput(input, "0");
@@ -627,12 +639,11 @@ describe("stats for multiple elements", () => {
) as HTMLInputElement;
expect(fontSize).toBeDefined();
// changing width does not affect text
UI.updateInput(width, "200");
expect(rectangle?.width).toBe(200);
expect(frame.width).toBe(200);
expect(text?.width).not.toBe(200);
expect(text?.width).toBe(200);
UI.updateInput(angle, "40");

View File

@@ -1,7 +1,7 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import { getBoundTextElement } from "@excalidraw/element";
import { isFrameLikeElement, isTextElement } from "@excalidraw/element";
import { isFrameLikeElement } from "@excalidraw/element";
import {
getSelectedGroupIds,
@@ -41,12 +41,6 @@ export const isPropertyEditable = (
element: ExcalidrawElement,
property: keyof ExcalidrawElement,
) => {
if (property === "height" && isTextElement(element)) {
return false;
}
if (property === "width" && isTextElement(element)) {
return false;
}
if (property === "angle" && isFrameLikeElement(element)) {
return false;
}