Skip to content

Do not render a soft hyphen that directly follows a visible hyphen [patch] - #149

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/135-soft-hyphen-after-hyphen
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/135-soft-hyphen-after-hyphen

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #135

What changed

ChunkWord splits a word after a visible hyphen and resets hyphenBefore. A soft hyphen right after that visible hyphen then took the "consecutive soft hyphens" branch, which set hyphenBefore = true on the next chunk. When the wrap broke at that point, the iterator appended a second -. So "well-known".NominalWordWrap(5, 1) produced "well--", which is 6 characters on a 5-character line.

That branch now sets hyphenBefore only when the previous chunk does not already end in -, which is the fix the triage suggested. The visible hyphen already marks the break, so the soft hyphen adds nothing. Consecutive soft hyphens after ordinary text keep their existing behaviour.

Tests

In StringExtensionsTests:

  • NominalWordWrapDoesNotDoubleAVisibleHyphenFollowedByASoftHyphen is the issue's case. It expects ["well-", "known"].
  • NominalWordWrapDoesNotDoubleAVisibleHyphenFollowedBySeveralSoftHyphens covers the same position with two soft hyphens.
  • NominalWordWrapKeepsAVisibleHyphenFollowedByASoftHyphenOnOneLineWhenItFits checks that the unbroken text is still well-known, with the soft hyphen stripped.

Verification

  • With StringExtensions.cs reverted, the first two tests fail. The third passes either way; it guards against regressions.
  • With the fix, the suite passes: 171 of 171.
  • The library builds for every target, from netstandard2.0 to net10.0, with 0 warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CzC1o7LFYHYaoWmVy1NLcp


Generated by Claude Code

ChunkWord marked the chunk after "well-" as hyphenated when a soft hyphen
followed the visible one, so a break there rendered "well--" and overhung
the line width. The visible hyphen already ends the chunk, so the soft
hyphen no longer marks the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CzC1o7LFYHYaoWmVy1NLcp
@sonarqubecloud

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

Development

Successfully merging this pull request may close these issues.

NominalWordWrap renders a double hyphen ("well--") when a soft hyphen directly follows a visible hyphen and the break lands there

2 participants