-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
55b6fb8
commit 884a313
Showing
7 changed files
with
99 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -845,6 +845,7 @@ IMoniker | |
IMonitor | ||
IMouse | ||
impl | ||
IMulti | ||
INDEXTOSTATEIMAGEMASK | ||
indierawk | ||
Infobar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/modules/launcher/PowerLauncher/Converters/HighlightTextConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters