mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Add 'src/modules/launcher/' from commit '28acd466b352a807910cebbc74477d3173b31511'
git-subtree-dir: src/modules/launcher git-subtree-mainline:852689b3dfgit-subtree-split:28acd466b3
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
|
||||
namespace Wox.Converters
|
||||
{
|
||||
public class HighlightTextConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] value, Type targetType, object parameter, CultureInfo cultureInfo)
|
||||
{
|
||||
var text = value[0] as string;
|
||||
var highlightData = value[1] as List<int>;
|
||||
|
||||
var textBlock = new Span();
|
||||
|
||||
if (highlightData == null || !highlightData.Any())
|
||||
{
|
||||
// No highlight data, just return the text
|
||||
return new Run(text);
|
||||
}
|
||||
|
||||
for (var i = 0; i < text.Length; i++)
|
||||
{
|
||||
var currentCharacter = text.Substring(i, 1);
|
||||
if (this.ShouldHighlight(highlightData, i))
|
||||
{
|
||||
textBlock.Inlines.Add(new Bold(new Run(currentCharacter)));
|
||||
}
|
||||
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 bool ShouldHighlight(List<int> highlightData, int index)
|
||||
{
|
||||
return highlightData.Contains(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user