diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index ece73691eb..56a0565689 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -845,6 +845,7 @@ IMoniker IMonitor IMouse impl +IMulti INDEXTOSTATEIMAGEMASK indierawk Infobar diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs index 0cfa83fd61..feb52497c3 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs @@ -114,7 +114,7 @@ namespace Microsoft.Plugin.Program.Programs // To set the title to always be the displayname of the packaged application result.Title = DisplayName; - result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData); + result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData; // Using CurrentCulture since this is user facing var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title); diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32Program.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32Program.cs index d0d9d20f96..85bebf7c07 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32Program.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32Program.cs @@ -234,7 +234,7 @@ namespace Microsoft.Plugin.Program.Programs }, }; - result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData); + result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData; // Using CurrentCulture since this is user facing var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title); diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs index 1379246484..b6b4218af7 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs @@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System if (titleMatch.Score > 0) { c.Score = titleMatch.Score; - c.SetTitleHighlightData(titleMatch.MatchData); + c.TitleHighlightData = titleMatch.MatchData; results.Add(c); } } diff --git a/src/modules/launcher/PowerLauncher/Converters/HighlightTextConverter.cs b/src/modules/launcher/PowerLauncher/Converters/HighlightTextConverter.cs new file mode 100644 index 0000000000..8730e3c525 --- /dev/null +++ b/src/modules/launcher/PowerLauncher/Converters/HighlightTextConverter.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Media; + +namespace PowerLauncher.Converters +{ + public class HighlightTextConverter : IMultiValueConverter + { + public object Convert(object[] value, Type targetType, object parameter, CultureInfo cultureInfo) + { +#pragma warning disable CA1062 // Validate arguments of public methods + var text = value[0] as string; +#pragma warning restore CA1062 // Validate arguments of public methods + var highlightData = value[1] as List; + var selected = value[2] as bool? == true; + + if (highlightData == null || !highlightData.Any()) + { + // No highlight data, just return the text + return new Run(text); + } + + var textBlock = new Span(); + for (var i = 0; i < text.Length; i++) + { + var currentCharacter = text.Substring(i, 1); + if (ShouldHighlight(highlightData, i)) + { + textBlock.Inlines.Add(new Run(currentCharacter) + { + FontWeight = FontWeights.SemiBold, + }); + } + else + { + textBlock.Inlines.Add(new Run(currentCharacter)); + } + } + + return textBlock; + } + + public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture) + { + return new[] { DependencyProperty.UnsetValue, DependencyProperty.UnsetValue }; + } + + private static bool ShouldHighlight(List highlightData, int index) + { + return highlightData.Contains(index); + } + } +} diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml b/src/modules/launcher/PowerLauncher/ResultList.xaml index e805e10476..260a717b6c 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml @@ -6,13 +6,18 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Behaviors="http://schemas.microsoft.com/xaml/behaviors" xmlns:p="clr-namespace:PowerLauncher.Properties" - mc:Ignorable="d" + xmlns:helper="clr-namespace:PowerLauncher.Helper" + xmlns:converters="clr-namespace:PowerLauncher.Converters" + xmlns:viewmodel="clr-namespace:PowerLauncher.ViewModel" + mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="720"> - + + +