mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #828] WordWrap(…) exceeds line length with punctuation marks #603
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#603
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @der-lyse on GitHub (Mar 19, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/828
Hi, first of all, thank you very much for this awesome library! :-)
I noticed that
WordWrap(…)does exceed the specified line length when a punctuation mark comes right after the line length. It's a bit tricky to explain, the following code illustrates this in more detail:go.mod:
main.go:
This program prints:
The last line is in fact five characters long, but the specified width was only four. I tested with period (
.), comma (,), semicolon (;), colon (:), exclamation mark (!), question mark (?) and plus (+) and they all result in the same behavior. There might be more characters. It doesn't matter that this input string ends with the period, the period could also be somewhere in the middle of the string and the resulting line length is exceeded there, too.Is this intended? I would have expected that the period or any of the other stated characters above are placed on their own line. Just like what happens if the period would be a regular character, number, dollar sign (
$), tilde (~) etc. So I hoped for this:Reducing the line length to three and the example code works flawlessly, the last two lines then are
marandk.as I expect them to be. So I suspect that it has to be something to do with the punctuation mark coming immediately after the line length is maxed out. I didn't look in the code, though.@rivo commented on GitHub (Mar 25, 2023):
The
WordWrap()function uses a very simple algorithm to determine possible line breaks. And as you found out, it also has bugs. I've been planning to rewrite this function for a while now. The new implementation will useuniseg's line breaking functionality which follows the Unicode standard and thus also works for languages other than English.I hope I will get some time soon to do this. But I will likely not fix this "old" implementation anymore.
Two more notes:
unisegyourself. Look atFirstLineSegmentInString()or theGraphemestype.TextAreaprimitive already uses this implementation. You can test it there to see how it behaves.@der-lyse commented on GitHub (Mar 26, 2023):
Thank you very much! I'll have a look at them.