Skip to content
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

Hyphens can cause wordwrap to exceed the limit #66

Open
JaredReisinger opened this issue Nov 19, 2023 · 0 comments · May be fixed by #67
Open

Hyphens can cause wordwrap to exceed the limit #66

JaredReisinger opened this issue Nov 19, 2023 · 0 comments · May be fixed by #67

Comments

@JaredReisinger
Copy link

When wordwrap.Write() encounters a hyphen, it immediately adds the existing space, word, and hyphen, without first checking to see if this would exceed the limit. This can cause the hyphen to extend beyond the limit.

Example: wordwrap.String("foo foo-foobar", 7) should return

1234567|  <-- limit
foo    |
foo-   |
foobar |

but actually returns:

1234567|  <-- limit
foo foo|- <-- hyphen beyond limit
foobar |
JaredReisinger added a commit to JaredReisinger/reflow that referenced this issue Nov 19, 2023
If the word-thus-far is exactly at the limit and `wordwrap.Write` sees a hyphen, it writes the word to the buffer *and the hyphen*, exceeding the limit. This change fixes that behavior by instead adding the byphen to the word "as normal", and *then* checking to see if the word will fit within the limit. If it does, only then will it flush the word to the buffer.

Fix muesli#66
@JaredReisinger JaredReisinger linked a pull request Nov 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant