-
-
Notifications
You must be signed in to change notification settings - Fork 749
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
g.wrapString sometimes removing last character #2572
Comments
I can't see any recent changes to |
Thanks for the report - yes, I doubt this is something that new - it probably came in when the word-splitting got added. |
Not a maintainer, but this line seems to be related: Consider what happens when we run the test case:
This doesn't happen with other strings like "testab"; since canSplitAfter is never set, these continue down the bottom of the loop when parsing the last char, and set endOfText. Then they can parse one final char PAST the end of the string (ch = -1), and copy in that last piece. My instinct is to refactor this function more, but one possible minimal fix is to add another copy of the line that sets endOfText just before the continue:
...after applying this patch, "test.a" is parsed correctly and |
Thanks for looking into this! That's great - patch applied. The whole wrapString function is a bit of a nightmare - I've already rewritten it once, but it's made particularly painful by it having to handle UTF8 (in some builds, not all) and the in-string bitmaps, and then the possibility that it'll have to split strings in the middle that wouldn't normally be split. Do you think you could post up an example of the UTF8 that fails? If you think you can come up with something tidier that works better then I'm all for it. It's been such a pain to get right though that if it turns out it's just another one-line change to fix UTF8 I'd be inclined to do that, as the current nasty solution has at least been used by thousands of people on Bangle.js so far and appears to almost be there. |
g.wrapString is removing the last character if the character before it is one of the canSplitAfter characters, eg . - or ,
This happens no matter how wide the wrap width is. For example -
g.wrapString('test.a', 100)
returnstest.
and nottest.a
Multiple characters after the split character work fine (
g.wrapString('test.aa', 100)
returnstest.aa
) as do spaces (g.wrapString('test a', 100)
returnstest a
)The text was updated successfully, but these errors were encountered: