Skip to content

Keep a hard-broken hyphen on the line with the rest of its word [patch] - #183

Open
matt-edmondson wants to merge 2 commits into
mainfrom
fix/182-lone-hyphen-line
Open

matt-edmondson wants to merge 2 commits into
mainfrom
fix/182-lone-hyphen-line

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #182

What changed

NominalWordWrap keeps a visible hyphen on the end of its chunk ("self-"). When that chunk was exactly one character too wide, the hard break left only the hyphen on the new line. The next chunk of the word could break before itself, so the line stayed holding nothing but -.

After a hard break leaves a remainder made only of hyphens, the next atom is joined to that line if it continues the same word (GlueSpace == false), then hard-broken from there as usual. Breaks at spaces and soft hyphens don't change.

Input, width Before After
self-explanatory, 4 self / - / expl / anat / ory self / -exp / lana / tory
abcde-fghij, 5 abcde / - / fghij abcde / -fghi / j
well-known e-mail, 4 well / - / know / n e- / mail well / -kno / wn / e- / mail
x-ray, 1 x / - / r / a / y unchanged

The hard-break loop moved into a HardBreak helper so NominalWordWrapIterator stays under the CA1502 complexity limit.

Tests


Generated by Claude Code

When a chunk like "self-" was exactly one character too wide, the hard break
left only its trailing hyphen on the new line, and the next chunk of the word
then broke before itself, so "self-explanatory" at width 4 wrapped to
"self" / "-" / "expl" / ... A line left holding only that hyphen run now takes
the next chunk of the same word and hard-breaks from there:
"self" / "-exp" / "lana" / "tory". Breaks at spaces and soft hyphens, and the
width-1 output, are unchanged.

Fixes #182

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5jAJ5C3wivQLYNkMm
Comment thread Extensions/StringExtensions.cs Fixed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5jAJ5C3wivQLYNkMm
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants