feat: use Intl.Segmenter as default wordSplit method#10606
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
Build Stats
|
|
Did a little research. The current version wraps lines, by default, each soft line break will swallow a whitespace character ( To maintain compatibility (consistent rendering results) and support languages that do not break lines with spaces, it is necessary to remember whether spaces are removed at each line wrap. I prefer to introduce a break change and adopt a new line wrapping method: pre-wrap. I looked at the line breaking method of Inkscape, as shown below: It behaves in accordance with CSS whitespace
Looking forward to feedback. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs 😔. Thank you for your contributions. |


Description
#10604
Hi @asturur, I will try to make it happen.
The plan is divided into two steps:
Intl.Segmenteras the default method, and use the previous method as fallback.In Action
The first step of the refactoring is to change the regular expression into a capture group to retain the separator, and filter out the useless empty array items in the
wordSplitreturn value.wrapLineno longer needs to insertinfix. To keep the results as consistent as possible with the previous ones, the single space at the beginning and end of the line is intentionally ignored.There are two inconsistencies after the refactoring:
\tand\rare replaced with spaces;\tand\rare retainedIs it necessary to maintain complete consistency with the pre-refactoring state?Edit: Just noticed that if it's not exactly the same, there will be issues with character counts etc.