mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
[Run] Highlight search text (#11635)
* Add bolded type * Inline get set * Fix * Update expect.txt IMulti Co-authored-by: Niels Laute <niels9001@hotmail.com> Co-authored-by: Clint Rutkas <clint@rutkas.com>
This commit is contained in:
parent
55b6fb8da6
commit
884a313f3c
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@ -845,6 +845,7 @@ IMoniker
|
|||||||
IMonitor
|
IMonitor
|
||||||
IMouse
|
IMouse
|
||||||
impl
|
impl
|
||||||
|
IMulti
|
||||||
INDEXTOSTATEIMAGEMASK
|
INDEXTOSTATEIMAGEMASK
|
||||||
indierawk
|
indierawk
|
||||||
Infobar
|
Infobar
|
||||||
|
@ -114,7 +114,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
|
|
||||||
// To set the title to always be the displayname of the packaged application
|
// To set the title to always be the displayname of the packaged application
|
||||||
result.Title = DisplayName;
|
result.Title = DisplayName;
|
||||||
result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData);
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||||
|
|
||||||
// Using CurrentCulture since this is user facing
|
// 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);
|
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
|
||||||
|
@ -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
|
// 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);
|
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
|
||||||
|
@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
|||||||
if (titleMatch.Score > 0)
|
if (titleMatch.Score > 0)
|
||||||
{
|
{
|
||||||
c.Score = titleMatch.Score;
|
c.Score = titleMatch.Score;
|
||||||
c.SetTitleHighlightData(titleMatch.MatchData);
|
c.TitleHighlightData = titleMatch.MatchData;
|
||||||
results.Add(c);
|
results.Add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<int>;
|
||||||
|
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<int> highlightData, int index)
|
||||||
|
{
|
||||||
|
return highlightData.Contains(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,13 +6,18 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:Behaviors="http://schemas.microsoft.com/xaml/behaviors"
|
xmlns:Behaviors="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
xmlns:p="clr-namespace:PowerLauncher.Properties"
|
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:DesignHeight="300"
|
||||||
d:DesignWidth="720">
|
d:DesignWidth="720">
|
||||||
|
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<ResourceDictionary>
|
|
||||||
|
|
||||||
|
<ResourceDictionary>
|
||||||
|
<converters:HighlightTextConverter x:Key="highlightTextConverter" />
|
||||||
|
|
||||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
<Style x:Key="FocusVisual">
|
<Style x:Key="FocusVisual">
|
||||||
<Setter Property="Control.Template">
|
<Setter Property="Control.Template">
|
||||||
@ -226,14 +231,21 @@
|
|||||||
Margin="-6,-2,0,0"
|
Margin="-6,-2,0,0"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
Source="{Binding Image}" />
|
Source="{Binding Image}" />
|
||||||
<TextBlock
|
<TextBlock AutomationProperties.Name="{x:Static p:Resources.Title}"
|
||||||
AutomationProperties.Name="{x:Static p:Resources.Title}"
|
x:Name="Title"
|
||||||
x:Name="Title" Grid.Column="1"
|
Grid.Column="1"
|
||||||
Text="{Binding Result.Title}"
|
FontSize="20"
|
||||||
FontWeight="SemiBold"
|
Margin="0,0,0,-2"
|
||||||
FontSize="20"
|
VerticalAlignment="Bottom">
|
||||||
Margin="0,0,0,-2"
|
<viewmodel:ResultsViewModel.FormattedText>
|
||||||
VerticalAlignment="Bottom"/>
|
<MultiBinding Converter="{StaticResource highlightTextConverter}">
|
||||||
|
<Binding Path="Result.Title" />
|
||||||
|
<Binding Path="Result.TitleHighlightData" />
|
||||||
|
<Binding RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type ListViewItem}}"
|
||||||
|
Path="IsSelected" />
|
||||||
|
</MultiBinding>
|
||||||
|
</viewmodel:ResultsViewModel.FormattedText>
|
||||||
|
</TextBlock>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
AutomationProperties.Name="{x:Static p:Resources.Subtitle}"
|
AutomationProperties.Name="{x:Static p:Resources.Subtitle}"
|
||||||
x:Name="Path"
|
x:Name="Path"
|
||||||
|
@ -20,7 +20,6 @@ namespace Wox.Plugin
|
|||||||
private ToolTipData _toolTipData;
|
private ToolTipData _toolTipData;
|
||||||
private string _pluginDirectory;
|
private string _pluginDirectory;
|
||||||
private string _icoPath;
|
private string _icoPath;
|
||||||
private IList<int> _titleHighlightData;
|
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
@ -103,30 +102,20 @@ namespace Wox.Plugin
|
|||||||
|
|
||||||
public Result(IList<int> titleHighlightData = null, IList<int> subTitleHighlightData = null)
|
public Result(IList<int> titleHighlightData = null, IList<int> subTitleHighlightData = null)
|
||||||
{
|
{
|
||||||
_titleHighlightData = titleHighlightData;
|
TitleHighlightData = titleHighlightData;
|
||||||
SubTitleHighlightData = subTitleHighlightData;
|
SubTitleHighlightData = subTitleHighlightData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#pragma warning disable CA2227 // Collection properties should be read only
|
||||||
/// Gets a list of indexes for the characters to be highlighted in Title
|
public IList<int> TitleHighlightData { get; set; }
|
||||||
/// </summary>
|
#pragma warning restore CA2227 // Collection properties should be read only
|
||||||
public IList<int> GetTitleHighlightData()
|
|
||||||
{
|
|
||||||
return _titleHighlightData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a list of indexes for the characters to be highlighted in Title
|
/// Gets or sets a list of indexes for the characters to be highlighted in SubTitle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetTitleHighlightData(IList<int> value)
|
#pragma warning disable CA2227 // Collection properties should be read only
|
||||||
{
|
public IList<int> SubTitleHighlightData { get; set; }
|
||||||
_titleHighlightData = value;
|
#pragma warning restore CA2227 // Collection properties should be read only
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a list of indexes for the characters to be highlighted in SubTitle
|
|
||||||
/// </summary>
|
|
||||||
public IList<int> SubTitleHighlightData { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets only results that originQuery match with current query will be displayed in the panel
|
/// Gets or sets only results that originQuery match with current query will be displayed in the panel
|
||||||
@ -161,7 +150,7 @@ namespace Wox.Plugin
|
|||||||
var equality = string.Equals(r?.Title, Title, StringComparison.Ordinal) &&
|
var equality = string.Equals(r?.Title, Title, StringComparison.Ordinal) &&
|
||||||
string.Equals(r?.SubTitle, SubTitle, StringComparison.Ordinal) &&
|
string.Equals(r?.SubTitle, SubTitle, StringComparison.Ordinal) &&
|
||||||
string.Equals(r?.IcoPath, IcoPath, StringComparison.Ordinal) &&
|
string.Equals(r?.IcoPath, IcoPath, StringComparison.Ordinal) &&
|
||||||
GetTitleHighlightData() == r.GetTitleHighlightData() &&
|
TitleHighlightData == r.TitleHighlightData &&
|
||||||
SubTitleHighlightData == r.SubTitleHighlightData;
|
SubTitleHighlightData == r.SubTitleHighlightData;
|
||||||
|
|
||||||
return equality;
|
return equality;
|
||||||
|
Loading…
Reference in New Issue
Block a user