-
Notifications
You must be signed in to change notification settings - Fork 9k
Rewrite HighlightedTextControl and remove HighlightedText #19130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The new
... and the new
/cc @e82eric since he's been working in this space |
DHowett
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments inline
| Documents::Run run; | ||
| run.Text(matchSeg); | ||
|
|
||
| if (runStyle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could [[unlikely]] this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about likely/unlikely too much. It's only a super subtle hint to the optimizer after all.
| if (lastPos < text.size()) | ||
| { | ||
| // checking lastPos here prevents a needless deep copy of the whole text in the no-match case | ||
| hstring tail{ lastPos == 0 ? text : hstring{ til::safe_slice_abs(text, lastPos, SIZE_T_MAX) } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: in general in this file, I should document WHY WE HAVE TEMPORARY HSTRINGS. i had to rediscover it for myself.
| HighlightedText Text; | ||
| Windows.UI.Xaml.Controls.TextBlock TextView { get; }; | ||
|
|
||
| IVector<HighlightedRun> HighlightedRuns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these feel so much better than object pointers, and have much better locality. also no AddRef and Release a jillion times.
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <Style TargetType="local:HighlightedTextControl"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we had a good way to roll up XAML resources, this could go down to microsoft.terminal.ui and be used everywhere
|
|
||
| <local:HighlightedTextControl Grid.Column="1" | ||
| HorizontalAlignment="Left" | ||
| HighlightedRuns="{x:Bind FilteredCommand.NameHighlights, Mode=OneWay}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ergonomically: I don't love that it's two properties, but man it makes the code so much simpler
| return winrt::unbox_value<type>(temp); \ | ||
| } \ | ||
| \ | ||
| if constexpr (std::is_same_v<type, winrt::hstring>) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually necessary because you can't unbox IInspectable nullptr as a hstring without exploding. And we do want the property to be nullable.
This is a strictly better version of the one that lives in TerminalSettingsEditor, and supersedes it, so it can live here.
This comment has been minimized.
This comment has been minimized.
carlos-zamora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of moving the dependency property macro to a shared spot. Happy that we'll be able to use that everywhere now.
Love that we can pass in special styling in the new control. Using the ranges makes sense too! Nice work :)
The bulk of this work is changing `Command::Name` (and its descendants like `GenerateName`) to support looking up names in English and in the local language. When matching a "palette item" with a "subtitle" (a new field introduced to store the English command name when the current language is not English), the weight of the subtitle is used only if it is greater than the weight of the name. This ensures that we do not penalize or over-promote results that contain similar Latin letters in both fields. Refs #19130, #19131, #19132, #19165 Closes #7039



This has been on my list for a while.
HighlightedTextControlis a XAML user control that contains a textblock and takes vector of
HighlightedText.HighlightedTextusestuples
(string, boolean). Allocating an entire object to store astring 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
HighlightedTextControlis a standard templated control, andsupports styling of both the inner text block and of the highlighted
runs.
It no longer takes a
HighlightedText, but rather a standard string anda set of runs (tuple
(int start, int end)); these can be stored moreefficiently, and this change moves the construction of text and runs
directly into
HighlightedTextControlitself as an implementationdetail rather than an API contract.
XAML Properties
Text: the string to highlightHighlightedRuns: a vector of(start, end)pairs, indicating whichregions are intended to be highlighted. Can be empty (which indicates
there is no highlight and that the entire string is styled normally.)
TextBlockStyle: theStyleapplied to the inner text block;optional; allows consumers to change how both normal and highlighted
text looks.
HighlightedRunStyle: aStyleapplied only to the highlighted runs;optional; allows consumers to change how highlighted text looks. If
left NULL, highlighted runs will be bold.
HighlightedRunStyleis a little bodgy. It only applies toRunobjects (which is fine, and XAML somewhat supports), but since
Runisnot a
FrameworkElement, it doesn't actually have aStylemember.We need to crack open the style and apply it manually, entry by entry.
FontWeightis special because XAML is a special little flower.