Skip to content

Conversation

@canstand
Copy link
Contributor

@canstand canstand commented May 15, 2025

Description

#10604

Hi @asturur, I will try to make it happen.
The plan is divided into two steps:

  1. Refactor the existing word segmentation method, and retain the separator in the returned array;
  2. Introduce Intl.Segmenter as 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 wordSplit return value.

wrapLine no longer needs to insert infix. 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:

  • Before: \t and \r are replaced with spaces;
  • After: \t and \r are retained
  • Before: one space is removed regardless of the number of spaces at the beginning and end of the line;
  • After: if there is more than one space at the beginning and end of the line, it remains unchanged

Is 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.

@codesandbox
Copy link

codesandbox bot commented May 15, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@github-actions
Copy link
Contributor

Build Stats

file / KB (diff) bundled minified
fabric 914.681 (+0.019) 301.494 (+0.044)

@canstand
Copy link
Contributor Author

Did a little research. The current version wraps lines, by default, each soft line break will swallow a whitespace character ([ \t\r]).

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:

Inkscape line wrap

It behaves in accordance with CSS whitespace white-space: pre-wrap;:

  • Spaces and tabs are preserved, and hang trailing whitespaces (not limited by the line box width).

CSS white-space: pre-wrap

Looking forward to feedback.

@stale
Copy link

stale bot commented Jul 19, 2025

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.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Issue marked as stale by the stale bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant