Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: text wrapping #7999

Merged
merged 77 commits into from
May 15, 2024
Merged

feat: text wrapping #7999

merged 77 commits into from
May 15, 2024

Conversation

ryan-di
Copy link
Member

@ryan-di ryan-di commented May 9, 2024

fix #7864
fix #4267 (partial)

This PR builds upon the side resizing PR. For text elements, when resized from "left" and "right" (or "w" and "e"), we support text wrapping and unwrapping.

follow-ups/TBD

  • drag-with-text-tool during creation to set the initial text width
  • paste of long text should limit the width (disable autoResize)
  • TBD: on font size change, keep width constant (upon further review it makes more sense from the viewpoint of user intention)

Copy link
Member

@ad1992 ad1992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ryan-di , did some quick testing of the PR and it looks good ✨
left some comments

packages/excalidraw/actions/actionTextAutoResize.ts Outdated Show resolved Hide resolved
@@ -1450,7 +1450,9 @@ export class ElementsChange implements Change<SceneElementsMap> {
continue;
}

redrawTextBoundingBox(boundText, container, elements, false);
redrawTextBoundingBox(boundText, container, elements, {
informMutation: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall, why is this not needed any more ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, I fell for the same. The informMutation=false is kept. Previously it was just a boolean flag.

Though through refactor the API signature change is no longer necessary so we can potential revert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted 🙂

}
if (transformHandleType.includes("s")) {
scaleY = (rotatedY - y1) / (y2 - y1);
if (transformHandleType !== "e" && transformHandleType !== "w") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this go into else of line 327 ? since you are checking if its e || w

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the if check here, scale from line 266 would not be zero and it'll trigger logic unrelated to e and w. I didn't really want to touch the logic that was working well for corner resizes. So the if check is here for that purpose.

packages/excalidraw/element/textElement.ts Show resolved Hide resolved
packages/excalidraw/element/textWysiwyg.test.tsx Outdated Show resolved Hide resolved
packages/excalidraw/element/textWysiwyg.test.tsx Outdated Show resolved Hide resolved
packages/excalidraw/element/textWysiwyg.tsx Outdated Show resolved Hide resolved
packages/excalidraw/element/textWysiwyg.tsx Outdated Show resolved Hide resolved
expect(text.height).toBe(height);
});

it("can be resized from w", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("can be resized from w", async () => {
it("text can be resized from w", async () => {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping the format: describe("text element") it("can be resized from w")

expect(text.autoResize).toBe(false);
});

it("has a minimum width when wrapped", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("has a minimum width when wrapped", async () => {
it("text has a minimum width when wrapped", async () => {

@ryan-di ryan-di merged commit 971b4d4 into master May 15, 2024
11 checks passed
@ryan-di ryan-di deleted the text-wrapping branch May 15, 2024 13:04
Copy link

sentry-io bot commented May 17, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ TypeError: Cannot read properties of undefined (reading 'width') resizeSingleTextElement(packages/excalidraw/ele... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why Can't I resize the box width or height wise? Text area tool
3 participants