add "Profiles" to search results

This commit is contained in:
Carlos Zamora
2026-05-12 11:41:29 -07:00
parent 3ee13c679f
commit 56aa5fc73f
3 changed files with 22 additions and 4 deletions

View File

@@ -66,8 +66,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
hstring runtimeObjContext{};
if (const auto profileVM = runtimeObj.try_as<Editor::ProfileViewModel>())
{
// No runtimeObjContext: profile name and icon should be enough
runtimeObjLabel = profileVM.Name();
runtimeObjContext = RS_(L"Nav_Profiles/Content");
}
else if (const auto colorSchemeVM = runtimeObj.try_as<Editor::ColorSchemeViewModel>())
{
@@ -258,6 +258,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
localizedEntry.DisplayTextNeutral = EnglishOnlyResourceLoader().GetLocalizedString(entry.ResourceName);
}
if (!entry.SecondaryLabelResourceName.empty())
{
localizedEntry.SecondaryLabelLocalized = GetLibraryResourceString(entry.SecondaryLabelResourceName);
}
localizedIndex.emplace_back(std::move(localizedEntry));
}
return localizedIndex;
@@ -342,7 +346,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
if (bestScore >= MinimumMatchScore)
{
scoredResults.emplace_back(bestScore, winrt::make<FilteredSearchResult>(index, &entry));
scoredResults.emplace_back(bestScore, winrt::make<FilteredSearchResult>(index, &entry, nullptr, std::nullopt, entry.SecondaryLabelLocalized));
}
}

View File

@@ -20,6 +20,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
winrt::hstring DisplayTextLocalized;
std::optional<winrt::hstring> DisplayTextNeutral = std::nullopt;
// No "Neutral" copy of SecondaryLabelLocalized: unlike DisplayText, the secondary
// label is display-only (rendered in the search result row's caption). It is never
// passed to the fuzzy matcher, so a single localized string is sufficient.
winrt::hstring SecondaryLabelLocalized;
const IndexEntry* Entry = nullptr;
std::array<std::pair<std::optional<winrt::hstring>, int>, 2> GetSearchableFields() const;

View File

@@ -85,6 +85,7 @@ $ClassMap = @{
ResourceName = "Nav_ProfileDefaults/Content"
NavigationParam = "GlobalProfile_Nav"
SubPage = "BreadcrumbSubPage::None"
SecondaryLabel = "Nav_Profiles/Content"
}
"Microsoft::Terminal::Settings::Editor::Profiles_Appearance" = @{
ResourceName = "Nav_ProfileDefaults/Content"
@@ -105,6 +106,7 @@ $ClassMap = @{
ResourceName = "Nav_AddNewProfile/Content"
NavigationParam = "AddProfile"
SubPage = "BreadcrumbSubPage::None"
SecondaryLabel = "Nav_Profiles/Content"
}
"Microsoft::Terminal::Settings::Editor::Profiles" = @{
ResourceName = "Nav_Profiles/Content"
@@ -161,6 +163,7 @@ foreach ($xamlFile in Get-ChildItem -Path $SourceDir -Filter *.xaml)
NavigationParam = $ClassMap[$pageClass].NavigationParam
SubPage = $ClassMap[$pageClass].SubPage
ElementName = $null # No specific element to navigate to, for the page itself
SecondaryLabel = $ClassMap[$pageClass].SecondaryLabel # Resource name for the result's sub-text (i.e. parent page name); $null if none
File = $filename
}
}
@@ -194,6 +197,7 @@ foreach ($xamlFile in Get-ChildItem -Path $SourceDir -Filter *.xaml)
NavigationParam = $ClassMap[$pageClass].NavigationParam
SubPage = $ClassMap[$pageClass].SubPage
ElementName = "AddNewButton"
SecondaryLabel = $ClassMap[$pageClass].SecondaryLabel
File = $filename
}
}
@@ -290,8 +294,9 @@ function FormatEntry($e)
$formattedResourceName = 'USES_RESOURCE(L"{0}")' -f $e.ResourceName
$formattedNavigationParam = 'L"{0}"' -f $e.NavigationParam # null Navigation param resolves to empty string
$formattedElementName = 'L"{0}"' -f $e.ElementName
$formattedSecondaryLabel = [string]::IsNullOrEmpty($e.SecondaryLabel) ? 'L""' : ('USES_RESOURCE(L"{0}")' -f $e.SecondaryLabel)
return " IndexEntry{{ {0}, {1}, {2}, {3} }}, // {4}" -f ($formattedResourceName, $formattedNavigationParam, $e.SubPage, $formattedElementName, $e.File)
return " IndexEntry{{ {0}, {1}, {2}, {3}, {4} }}, // {5}" -f ($formattedResourceName, $formattedNavigationParam, $e.SubPage, $formattedElementName, $formattedSecondaryLabel, $e.File)
}
function FormatEntries($es) {
@@ -299,7 +304,7 @@ function FormatEntries($es) {
}
# Sort and remove duplicates
$entries = $entries | Sort-Object ResourceName, ParentPage, NavigationParam, SubPage, ElementName, File -Unique
$entries = $entries | Sort-Object ResourceName, ParentPage, NavigationParam, SubPage, ElementName, SecondaryLabel, File -Unique
$buildTimeEntries = @()
$profileEntries = @()
@@ -355,6 +360,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// x:Name of the SettingContainer to navigate to on the page (i.e. "DefaultProfile")
wil::zwstring_view ElementName;
// Resource name of the search result's secondary label (i.e. parent page name like "Nav_Profiles/Content").
// Empty if the entry has no secondary label.
// NOTE: wrapped in USES_RESOURCE() like ResourceName when non-empty.
wil::zwstring_view SecondaryLabelResourceName;
};
const std::array<IndexEntry, $($buildTimeEntries.Count)>& LoadBuildTimeIndex();