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

Add text wrapping to FreeText editors (issue 18191) #19345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

avdoseferovic
Copy link

I'm aware that there is already an PR open with the similar promise, but the implementation is different.

Note: please read the gist comments https://gist.github.com/bennadel/033e0158f47bff9e066016f99567ebba
This solution might face performance issues with very large text being added.

Fixes: #18191

Before
Screen.Recording.2025-01-18.at.23.24.58.mov
After
Screen.Recording.2025-01-18.at.23.26.22.mov

@Snuffleupagus Snuffleupagus changed the title feat: add text wraping to freetext [18191] Add text wrapping to FreeText editors (issue 18191) Jan 19, 2025
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Please improve the commit message (see the commit history of the project for examples of how we usually write them):

  • Note the updated PR title, which is thus also a good "title" for the commit message.
  • Generally you want more than a single line in the commit message, such that relevant context is available also on the Git command line.

Comment on lines +694 to +696
// Not sure why we need the -16px but it's neccessary to prevent
// text shifting when user finishes typing.
this.div.style.maxWidth = `calc(100% - ${this.div.style.left} - 16px)`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks too "magical", and really needs to be properly understood (and improved).

Copy link
Author

Choose a reason for hiding this comment

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

the idea behind this is to subtract the left position (which is already a percentage) from 100% and that way we always ensure that the text editor will not go out of bounds(and will be forced to wrap into the next line).

I still need to find why the 16px is needed, maybe the internal padding of the editor also has effect on the max-width property.

Copy link
Author

Choose a reason for hiding this comment

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

or better visually explained, we end up with this: (this is only when you click on the right edge)
Screenshot 2025-01-19 at 20 30 38

src/display/editor/freetext.js Outdated Show resolved Hide resolved
Text wrapping is ensured by preventing the FreeText editor from going
out of bounds.

- max-width is a formula of (100% of the parentElement - the left % of the editor element)
- this ensures that clicking on the very right edge of the document does
- not create the editor out of bounds.
@avdoseferovic avdoseferovic force-pushed the feat/add-text-wraping-to-freetext branch from cbb1889 to cd76eca Compare January 19, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add wrapping/resizing for Freetext annotations
2 participants