[PR #19130] Rewrite HighlightedTextControl and remove HighlightedText #31715

Open
opened 2026-01-31 09:49:05 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19130

State: closed
Merged: Yes


This has been on my list for a while.

HighlightedTextControl is a XAML user control that contains a text
block and takes vector of HighlightedText. HighlightedText uses
tuples (string, boolean). Allocating an entire object to store a
string and an integer felt like a waste, especially when we were doing
it thousands of times for the command palette and just to pass them
into another object that stores a string and a few more integers
(Run).

The new HighlightedTextControl is a standard templated control, and
supports styling of both the inner text block and of the highlighted
runs.

It no longer takes a HighlightedText, but rather a standard string and
a set of runs (tuple (int start, int end)); these can be stored more
efficiently, and this change moves the construction of text and runs
directly into HighlightedTextControl itself as an implementation
detail rather than an API contract.

XAML Properties

  • Text: the string to highlight
  • HighlightedRuns: a vector of (start, end) pairs, indicating which
    regions are intended to be highlighted. Can be empty (which indicates
    there is no highlight and that the entire string is styled normally.)
  • TextBlockStyle: the Style applied to the inner text block;
    optional; allows consumers to change how both normal and highlighted
    text looks.
  • HighlightedRunStyle: a Style applied only to the highlighted runs;
    optional; allows consumers to change how highlighted text looks. If
    left NULL, highlighted runs will be bold.

HighlightedRunStyle is a little bodgy. It only applies to Run
objects (which is fine, and XAML somewhat supports), but since Run is
not a FrameworkElement, it doesn't actually have a Style member.
We need to crack open the style and apply it manually, entry by entry.
FontWeight is special because XAML is a special little flower.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19130 **State:** closed **Merged:** Yes --- This has been on my list for a while. `HighlightedTextControl` is a XAML user control that contains a text block and takes vector of `HighlightedText`. `HighlightedText` uses tuples `(string, boolean)`. Allocating an entire object to store a string and an integer felt like a waste, especially when we were doing it thousands of times for the command palette _and just to pass them into another object that stores a string and a few more integers (`Run`)._ The new `HighlightedTextControl` is a standard templated control, and supports styling of both the inner text block and of the highlighted runs. It no longer takes a `HighlightedText`, but rather a standard string and a set of runs (tuple `(int start, int end)`); these can be stored more efficiently, and this change moves the construction of text and runs directly into `HighlightedTextControl` itself as an implementation detail rather than an API contract. ### XAML Properties - `Text`: the string to highlight - `HighlightedRuns`: a vector of `(start, end)` pairs, indicating which regions are intended to be highlighted. Can be empty (which indicates there is no highlight and that the entire string is styled normally.) - `TextBlockStyle`: the `Style` applied to the inner text block; optional; allows consumers to change how both normal and highlighted text looks. - `HighlightedRunStyle`: a `Style` applied only to the highlighted runs; optional; allows consumers to change how highlighted text looks. If left NULL, highlighted runs will be bold. `HighlightedRunStyle` is a little bodgy. It only applies to `Run` objects (which is fine, and XAML somewhat supports), but since `Run` is not a `FrameworkElement`, it _doesn't actually have a `Style` member._ We need to crack open the style and apply it manually, entry by entry. `FontWeight` is special because XAML is a special little flower.
claunia added the pull-request label 2026-01-31 09:49:05 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31715