Skip to content

Report unnamed TextStyle colours as fixed-width #AARRGGBB so they round trip [patch] - #168

Merged
matt-edmondson merged 2 commits into
mainfrom
claude/issue-142-color-roundtrip
Sep 29, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
claude/issue-142-color-roundtrip

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #142

What was wrong

TextStyle.Foreground/Background returned Color.Name. For an unnamed colour that is Convert.ToString(argb, 16), which drops leading zeros:

  • alpha 0x01–0x0F gave a 7-digit name (a123456), which the setter rejects with ArgumentException
  • alpha 0x00 gave 6 digits (123456), which the setter reads as opaque RRGGBB, so the copy silently became FF123456
  • Color.FromArgb(0) gave "0", which also throws

Change

  • A new FormatColor helper backs both getters: known colours keep their name, every other colour is emitted as fixed-width #AARRGGBB, which TryParseHexColor already accepts.
  • The TryParseHexColor doc now names the form the getters emit.

Tests

  • UnnamedColorRoundTripsThroughTheStringProperty is now data-driven over alpha 0xFF, 0x80, 0x10, 0x0F, 0x0A, 0x01, 0x00, 0x00000001 and 0, for both foreground and background.
  • UnnamedColorReadsBackAsFixedWidthHex pins the #0A123456 format.
  • With the fix reverted, 7 of those cases fail (throws or ARGB mismatch). With it, the full suite passes (205/205).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NFZqEcFcZzrKRzQvofupG6


Generated by Claude Code

…y round trip [patch]

The Foreground/Background getters returned Color.Name, which for an
unnamed colour drops leading zeros. An alpha of 0x01-0x0F gave a
seven-digit name the setter rejected, and an alpha of 0x00 gave six
digits the setter read back as an opaque RRGGBB. Known colours keep
their names; every other colour is now emitted as #AARRGGBB.

Fixes #142

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NFZqEcFcZzrKRzQvofupG6
…ternary [patch]

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit e8c54cd into main Sep 29, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/issue-142-color-roundtrip branch September 29, 2026 04:51
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.

TextStyle.Foreground/Background round trip throws or drops alpha for colors with alpha below 0x10

2 participants