Skip to content

fix(text): Default null highlighter brushes like WinUI - #26725

Open
mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/text-highlighter-default-brushes
Open

mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/text-highlighter-default-brushes

Conversation

@mikernet

@mikernet mikernet commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24747; part of the epic #26728

PR Type:

🐞 Bugfix

What changed? 🚀

On WinUI, a TextHighlighter whose Background or Foreground is left unset is drawn with the theme's TextControlHighlighterBackground and TextControlHighlighterForeground (yellow and black in the light and dark themes). On Skia, TextBlock drew no background at all for an unset Background, and used a hard-coded black for an unset Foreground, so an app that overrides those resources didn't get its colors either.

UnicodeText.Draw now resolves an unset brush through TextHighlightRenderer.GetDefaultHighlighterBrushes, the helper ported from WinUI's TextHighlightRenderer.cpp, which looks both keys up in the application's resources. Each brush falls back on its own, like IterateMergedHighlighters: a highlighter with only Foreground set gets the default background, and one with only Background set gets the default foreground. The lookup only happens when a highlighter actually has an unset brush, so the selection highlighter (which always sets both) costs nothing extra.

Visible change for existing apps. A TextBlock highlighter that sets only Foreground, the usual way to recolor part of a text, now also paints the default yellow background behind that range, as it does on WinUI. To keep the old look, set Background to a transparent brush (new SolidColorBrush(Colors.Transparent)): that draws no fill on WinUI or on Skia, and the text keeps the highlighter's Foreground.

What it reaches:

  • TextBlock: fixed.
  • RichTextBlock and RichTextBlockOverflow: unchanged. They still draw through the legacy ParsedText engine, which already falls back to the default background. They will pick up this path when they move to UnicodeText.
  • TextBox, PasswordBox and RichEditBox: they draw through UnicodeText too, but only with their selection highlighter, which sets both brushes, so their output doesn't change.
  • With high-contrast adjustment on, a TextBlock highlighter with an unset Background now gets the high-contrast selection colors, like one with an explicit Background, instead of the plain backplate.

Validation

Runtime, Skia Desktop (Win32): new tests in Given_TextBlock, which find the highlight by color in a screenshot:

  • When_TextHighlighter_Has_No_Brushes: yellow background and black text over the highlighted word only.
  • When_TextHighlighter_Has_No_Brushes_Dark_Theme: the same in the dark application theme.
  • When_TextHighlighter_Has_Only_Foreground: yellow background, the highlighter's text color.
  • When_TextHighlighter_Has_Only_Background: the highlighter's background, with the text in the theme's default foreground. The test overrides TextControlHighlighterForeground, since the old hard-coded black is also the light and dark default.
  • When_TextHighlighter_Default_Brushes_Are_Overridden: with both resources overridden in Application.Resources, the overrides are used.
  • When_TextHighlighter_Has_Transparent_Background: a transparent Background with a Foreground draws no fill, only the recolored text (the way to keep the old look).

Plus Given_RichTextBlock_Highlighters.When_Highlighter_Has_No_Brushes, which pins the yellow RichTextBlock already draws over the highlighted word and not over the rest of the text. The control is sized to its text, so both checked areas sit over glyphs; highlighting the whole text makes it fail.

  • All seven pass, in 3 runs out of 3.
  • Without the fix, the five default-brush TextBlock tests fail (no yellow background, or black text instead of the overridden foreground). The transparent-background test and the RichTextBlock one pass both before and after, since they pin behavior that doesn't change.
  • The RichTextBlock group (Given_RichTextBlock|Given_SkiaTextFormatter|Given_BlockLayoutEngine|Given_HyperlinkAutomation, 208 cases) and the TextBlock/TextBox/RichEditBox/PasswordBox group (1,578 cases): against master, no case went from pass to fail. The only differences are the new cases, all passing. The two failures and one inconclusive in the second group fail on master too.

Runtime, native WinUI (WinAppSDK): the seven tests pass. Before writing them, I measured WinUI: an unset Background gives #FFFFFF00, an unset Foreground gives black even over a red run, each brush falls back on its own, and an app override of either resource is used. The WinUI app ran in the dark application theme, since WinUI can't switch it at runtime; the light values come from WinUI's generic.xaml, where they are the same.

Compile: Uno.UI and the runtime tests project build with analyzers and code style on, with no warning or error.

Not in this PR: a non-SolidColorBrush highlighter brush, which WinUI rejects (#24684), is left as is.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features): not applicable, the behavior now matches WinUI.
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes: no API change. The rendering change above is a fix toward WinUI's behavior, with a transparent Background to opt out.
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

A TextHighlighter with no Background drew no highlight in a TextBlock,
and one with no Foreground used a fixed black. Like WinUI, resolve
an unset brush to the theme's TextControlHighlighterBackground and
TextControlHighlighterForeground, each on its own.

Fixes unoplatform#24747
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@mergify

mergify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

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.

TextBlock TextHighlighter with no Background paints no highlight; WinUI falls back to the yellow TextControlHighlighterBackground

1 participant