Skip to content

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

Description

@matt-edmondson

What's wrong

ChunkWord (Extensions/StringExtensions.cs:347-389) splits a word after a visible hyphen. It adds the chunk "well-" and resets hyphenBefore = false (:375-380). If the next character is a soft hyphen (U+00AD), then current is empty and chunks.Count > 0, so the branch at :365-369 sets hyphenBefore = true for the following chunk. When NominalWordWrapIterator later breaks before that chunk, it appends '-' to the upper line (:284-287). That line already ends with the visible hyphen, so the output is "well--".

The XML doc (:221-226) says a soft hyphen "renders as a hyphen only when a break lands there". A break right after an existing visible hyphen needs no extra hyphen; adding one produces visibly wrong text and makes the line overhang the requested width.

Failure scenario

"well-known".NominalWordWrap(5, 1)
  • Expected: ["well-", "known"]
  • Actual: ["well--", "known"]. The first line is 6 characters, which exceeds maxCharsPerLine = 5.

Text run through automatic soft-hyphenation commonly has a U+00AD inserted next to existing hyphens, so this input is realistic.

How verified

Built the library for net10.0 and ran a console program that prints each line of "well-known".NominalWordWrap(5, 1):

[well--]
[known]

Suggested fix / acceptance criteria

  • In ChunkWord, when a soft hyphen immediately follows a visible hyphen (the previous chunk ends in '-' and current is empty), do not set hyphenBefore. The visible-hyphen break already covers that position.
  • Alternatively, skip the line.Append('-') in the iterator when the line already ends with '-'.
  • Add a test asserting that "well-known".NominalWordWrap(5, 1) yields ["well-", "known"].

Activity

  1. matt-edmondson commented on Sep 27, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Low. It is a cosmetic double hyphen, and the line overhangs maxCharsPerLine by one character. It only happens when a soft hyphen sits directly after a visible hyphen and the break lands there.
    • Area / suggested owner: Extensions/StringExtensions.cs (ChunkWord / NominalWordWrapIterator)
    • Duplicates / in progress: None found. No open PR.
    • Notes: Fixing it in ChunkWord (don't set hyphenBefore right after a chunk that ends in -) keeps the iterator simple. Add the "well-known" test from the issue.

    Generated by Claude Code

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

Metadata

Metadata

Labels

bugSomething isn't workingreadyFully specified; implement as written

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions