feat: use Intl.Segmenter as default wordSplit method #10606
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


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.