feat(): Add Textbox textOverflow option#8526
Conversation
|
Hi @wxul |
ShaMan123
left a comment
There was a problem hiding this comment.
I will test it and comment in case I have more findings.
Good job!
Could you add a line to the CHANGELOG?
| * Will block splitByGrapheme option! | ||
| * @type Boolean | ||
| */ | ||
| overflowBreakWord: boolean; |
There was a problem hiding this comment.
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.
I agree, but how to deal with the previous versions of splitByGrapheme ?
There was a problem hiding this comment.
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.
introduced resolveTextOverflowStrategy
There was a problem hiding this comment.
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
widthis 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.
@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 onsdfgand 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.
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) |
|
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
splitByGraphemedoes not meet my needsDescription
The Textbox adds an
overflowBreakWordoption 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: truefabric-textbox-slipByGrapheme.mp4
Textbox with
overflowBreakWord: truefabric-textbox-overflowBreakWord.mp4