-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(): Add Textbox textOverflow
option
#8526
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
base: master
Are you sure you want to change the base?
Conversation
Hi @wxul |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test it and comment in case I have more findings.
Good job!
Could you add a line to the CHANGELOG?
src/shapes/textbox.class.ts
Outdated
* Will block splitByGrapheme option! | ||
* @type Boolean | ||
*/ | ||
overflowBreakWord: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should introduce a breakLineStrategy
prop or something similar instead of a flag and perhaps make splitByGrapheme
an option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but how to deal with the previous versions of splitByGrapheme
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can mark it as deprecated
and introduce its predecessor and have logic supporting falling back to splitByGrapheme
.
Or we break.
@asturur ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduced resolveTextOverflowStrategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have deprecated splitByGrapheme
in favor of textOverflow
. Is the naming good enough?
I have tested live and have a few concerns:
- should initial size be equal to the largest word if
width
is not set? This question might be a non issue due to #8470 . Current behavior is like splitByGrapheme, width is set to the largest char. - lines with whitespace only should be dropped unless last line I believe
Text value: fabric.js sandbox sfdg sdfg sdfg sdfgsssa dsfgert ergertq wtrh srth
fabric.js.sandbox.-.Google.Chrome.2022-12-20.17-58-50_Trim.mp4
- After this is merged we need to visit #8470 and see how it works and add a test perhaps.
After looking into cursor position I see there is an unrelated bug/wrong behavior of the cursor with line breaking. |
I have no opinion, I simply solved my problem and made a pr by the way, your opinion will be more comprehensive than mine. |
fair enough |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asturur @melchiar I need your help here to determine 2 issues:
- CharSpacing + line breaking not on the first word still keeps some spacing
See how it breaks with spacing onsdfg
and precisely onfabric.js
fabric.js.sandbox.-.Google.Chrome.2022-12-21.15-04-37_Trim.mp4
- Style map generation, see comment
I am done here.
@wxul Thanks!
TODO
- cursor is off with text overflow. It should break before the last space of a line (if exists) to the beginning of the next. This doesn't happen. Should be addressed in a follow.
- ws at EOL in default breaking strategy
realLineCount++; | ||
} else if ( | ||
!this.splitByGrapheme && | ||
!this.resolveTextOverflowStrategy() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guessing this...
no tests and not enough context to understand this.
Why doesn't it use the split lines?
textOverflow
option
Hi @wxul this PR looks good to me, i m focused those days in finishing the TS migration and i would like to look at this shortly after. |
(this feature was requested in the past too, we had an implementation but then we decided to do no exagerate with options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated from master
Code looks good to me, though I'm wondering if maybe the css property |
I noticed an issue with this PR. If we keep pressing space, the lines are getting broken. |
@umtdemr can you provide a video? |
Screen.Recording.2023-02-23.at.2.36.13.PM.mov |
nice! |
Motivation
Textbox option
splitByGrapheme
does not meet my needsDescription
The Textbox adds an
overflowBreakWord
option to achieve a result similar to the css propertyoverflow-wrap: break-word
. Unlike the default, the width can be adjusted, and unlikesplitByGrapheme: true
, the word will be kept as complete as possible.MDN: overflow-wrap
Changes
Gist
In Action
Textbox default
fabric-textbox-default.mp4
Textbox with
splitByGrapheme: true
fabric-textbox-slipByGrapheme.mp4
Textbox with
overflowBreakWord: true
fabric-textbox-overflowBreakWord.mp4