mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Merge pull request #85 from SysC0mp/highlight-how-results-matched
Highlight how results matched
This commit is contained in:
@@ -27,7 +27,6 @@ namespace Wox.Plugin.ControlPanel
|
||||
Directory.CreateDirectory(iconFolder);
|
||||
}
|
||||
|
||||
|
||||
foreach (ControlPanelItem item in controlPanelItems)
|
||||
{
|
||||
if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null)
|
||||
@@ -43,7 +42,10 @@ namespace Wox.Plugin.ControlPanel
|
||||
|
||||
foreach (var item in controlPanelItems)
|
||||
{
|
||||
item.Score = Score(item, query.Search);
|
||||
var titleMatch = StringMatcher.FuzzySearch(query.Search, item.LocalizedString);
|
||||
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, item.InfoTip);
|
||||
|
||||
item.Score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
||||
if (item.Score > 0)
|
||||
{
|
||||
var result = new Result
|
||||
@@ -66,6 +68,16 @@ namespace Wox.Plugin.ControlPanel
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
if (item.Score == titleMatch.Score)
|
||||
{
|
||||
result.TitleHighlightData = titleMatch.MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.SubTitleHighlightData = subTitleMatch.MatchData;
|
||||
}
|
||||
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
@@ -74,26 +86,6 @@ namespace Wox.Plugin.ControlPanel
|
||||
return panelItems;
|
||||
}
|
||||
|
||||
private int Score(ControlPanelItem item, string query)
|
||||
{
|
||||
var scores = new List<int> {0};
|
||||
if (!string.IsNullOrEmpty(item.LocalizedString))
|
||||
{
|
||||
var score1 = StringMatcher.FuzzySearch(query, item.LocalizedString).ScoreAfterSearchPrecisionFilter();
|
||||
var score2 = StringMatcher.ScoreForPinyin(item.LocalizedString, query);
|
||||
scores.Add(score1);
|
||||
scores.Add(score2);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(item.InfoTip))
|
||||
{
|
||||
var score1 = StringMatcher.FuzzySearch(query, item.InfoTip).ScoreAfterSearchPrecisionFilter();
|
||||
var score2 = StringMatcher.ScoreForPinyin(item.InfoTip, query);
|
||||
scores.Add(score1);
|
||||
scores.Add(score2);
|
||||
}
|
||||
return scores.Max();
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_name");
|
||||
|
||||
@@ -55,6 +55,7 @@ namespace Wox.Plugin.Everything
|
||||
r.Title = Path.GetFileName(path);
|
||||
r.SubTitle = path;
|
||||
r.IcoPath = path;
|
||||
r.TitleHighlightData = StringMatcher.FuzzySearch(keyword, Path.GetFileName(path)).MatchData;
|
||||
r.Action = c =>
|
||||
{
|
||||
bool hide;
|
||||
@@ -78,6 +79,7 @@ namespace Wox.Plugin.Everything
|
||||
return hide;
|
||||
};
|
||||
r.ContextData = s;
|
||||
r.SubTitleHighlightData = StringMatcher.FuzzySearch(keyword, path).MatchData;
|
||||
results.Add(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.Folder
|
||||
@@ -58,13 +59,14 @@ namespace Wox.Plugin.Folder
|
||||
return results;
|
||||
}
|
||||
|
||||
private Result CreateFolderResult(string title, string path, string queryActionKeyword)
|
||||
private Result CreateFolderResult(string title, string path, Query query)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Title = title,
|
||||
IcoPath = path,
|
||||
SubTitle = "Ctrl + Enter to open the directory",
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
|
||||
Action = c =>
|
||||
{
|
||||
if (c.SpecialKeyState.CtrlPressed)
|
||||
@@ -82,7 +84,9 @@ namespace Wox.Plugin.Folder
|
||||
}
|
||||
|
||||
string changeTo = path.EndsWith("\\") ? path : path + "\\";
|
||||
_context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo);
|
||||
_context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
|
||||
changeTo :
|
||||
query.ActionKeyword + " " + changeTo);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -93,8 +97,8 @@ namespace Wox.Plugin.Folder
|
||||
string search = query.Search.ToLower();
|
||||
var userFolderLinks = _settings.FolderLinks.Where(
|
||||
x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase));
|
||||
var results = userFolderLinks.Select(item => CreateFolderResult(item.Nickname, item.Path, query.ActionKeyword))
|
||||
.ToList();
|
||||
var results = userFolderLinks.Select(item =>
|
||||
CreateFolderResult(item.Nickname, item.Path, query)).ToList();
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -132,34 +136,41 @@ namespace Wox.Plugin.Folder
|
||||
incompleteName = search.Substring(index + 1).ToLower();
|
||||
search = search.Substring(0, index + 1);
|
||||
if (!Directory.Exists(search))
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // folder exist, add \ at the end of doesn't exist
|
||||
{
|
||||
// folder exist, add \ at the end of doesn't exist
|
||||
if (!search.EndsWith("\\"))
|
||||
{
|
||||
search += "\\";
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(CreateOpenCurrentFolderResult(incompleteName, search));
|
||||
|
||||
|
||||
var directoryInfo = new DirectoryInfo(search);
|
||||
|
||||
var searchOption= SearchOption.TopDirectoryOnly;
|
||||
var searchOption = SearchOption.TopDirectoryOnly;
|
||||
incompleteName += "*";
|
||||
|
||||
if (incompleteName.StartsWith(">")) // give the ability to search all folder when starting with >
|
||||
// give the ability to search all folder when starting with >
|
||||
if (incompleteName.StartsWith(">"))
|
||||
{
|
||||
searchOption = SearchOption.AllDirectories;
|
||||
incompleteName = incompleteName.Substring(1);
|
||||
}
|
||||
|
||||
string searchNickname = new FolderLink { Path = query.Search }.Nickname;
|
||||
try
|
||||
{
|
||||
// search folder and add results
|
||||
var directoryInfo = new DirectoryInfo(search);
|
||||
var fileSystemInfos = directoryInfo.GetFileSystemInfos(incompleteName, searchOption);
|
||||
|
||||
foreach (var fileSystemInfo in fileSystemInfos)
|
||||
@@ -168,12 +179,12 @@ namespace Wox.Plugin.Folder
|
||||
|
||||
var result =
|
||||
fileSystemInfo is DirectoryInfo
|
||||
? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query.ActionKeyword)
|
||||
: CreateFileResult(fileSystemInfo.FullName);
|
||||
? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query)
|
||||
: CreateFileResult(fileSystemInfo.FullName, query);
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is UnauthorizedAccessException || e is ArgumentException)
|
||||
{
|
||||
@@ -188,12 +199,13 @@ namespace Wox.Plugin.Folder
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Result CreateFileResult(string filePath)
|
||||
private static Result CreateFileResult(string filePath, Query query)
|
||||
{
|
||||
var result = new Result
|
||||
{
|
||||
Title = Path.GetFileName(filePath),
|
||||
IcoPath = filePath,
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
|
||||
Action = c =>
|
||||
{
|
||||
try
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Http;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
@@ -142,6 +143,8 @@ namespace Wox.Plugin.PluginManagement
|
||||
Title = r.name,
|
||||
SubTitle = r.description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.name).MatchData,
|
||||
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.description).MatchData,
|
||||
Action = c =>
|
||||
{
|
||||
MessageBoxResult result = MessageBox.Show("Are you sure you wish to install the \'" + r.name + "\' plugin",
|
||||
@@ -191,6 +194,8 @@ namespace Wox.Plugin.PluginManagement
|
||||
Title = plugin.Name,
|
||||
SubTitle = plugin.Description,
|
||||
IcoPath = plugin.IcoPath,
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Name).MatchData,
|
||||
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Description).MatchData,
|
||||
Action = e =>
|
||||
{
|
||||
UnInstallPlugin(plugin);
|
||||
|
||||
@@ -78,8 +78,8 @@ namespace Wox.Plugin.Program
|
||||
}
|
||||
|
||||
var results1 = win32.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
|
||||
var results2 = uwps.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace Wox.Plugin.Program.Programs
|
||||
|
||||
public UWP(Package package)
|
||||
{
|
||||
|
||||
Location = package.InstalledLocation.Path;
|
||||
Name = package.Id.Name;
|
||||
FullName = package.Id.FullName;
|
||||
@@ -266,11 +265,9 @@ namespace Wox.Plugin.Program.Programs
|
||||
|
||||
private int Score(string query)
|
||||
{
|
||||
var score1 = StringMatcher.FuzzySearch(query, DisplayName).ScoreAfterSearchPrecisionFilter();
|
||||
var score2 = StringMatcher.ScoreForPinyin(DisplayName, query);
|
||||
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
|
||||
var score4 = StringMatcher.ScoreForPinyin(Description, query);
|
||||
var score = new[] { score1, score2, score3, score4 }.Max();
|
||||
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
var score = new[] { displayNameMatch.Score, descriptionMatch.Score }.Max();
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -299,14 +296,18 @@ namespace Wox.Plugin.Program.Programs
|
||||
Description.Substring(0, DisplayName.Length) == DisplayName)
|
||||
{
|
||||
result.Title = Description;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Description))
|
||||
{
|
||||
result.Title = $"{DisplayName}: {Description}";
|
||||
var title = $"{DisplayName}: {Description}";
|
||||
result.Title = title;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Title = DisplayName;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,10 @@ namespace Wox.Plugin.Program.Programs
|
||||
|
||||
private int Score(string query)
|
||||
{
|
||||
var score1 = StringMatcher.FuzzySearch(query, Name).ScoreAfterSearchPrecisionFilter();
|
||||
var score2 = StringMatcher.ScoreForPinyin(Name, query);
|
||||
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
|
||||
var score4 = StringMatcher.ScoreForPinyin(Description, query);
|
||||
var score5 = StringMatcher.FuzzySearch(query, ExecutableName).ScoreAfterSearchPrecisionFilter();
|
||||
var score = new[] { score1, score2, score3, score4, score5 }.Max();
|
||||
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
|
||||
var score = new[] { nameMatch.Score, descriptionMatch.Score, executableNameMatch.Score }.Max();
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -75,14 +73,18 @@ namespace Wox.Plugin.Program.Programs
|
||||
Description.Substring(0, Name.Length) == Name)
|
||||
{
|
||||
result.Title = Description;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Description))
|
||||
{
|
||||
result.Title = $"{Name}: {Description}";
|
||||
var title = $"{Name}: {Description}";
|
||||
result.Title = title;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Title = Name;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -56,12 +56,21 @@ namespace Wox.Plugin.Sys
|
||||
var results = new List<Result>();
|
||||
foreach (var c in commands)
|
||||
{
|
||||
var titleScore = StringMatcher.FuzzySearch(query.Search, c.Title).ScoreAfterSearchPrecisionFilter();
|
||||
var subTitleScore = StringMatcher.FuzzySearch(query.Search, c.SubTitle).ScoreAfterSearchPrecisionFilter();
|
||||
var score = Math.Max(titleScore, subTitleScore);
|
||||
var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
|
||||
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle);
|
||||
|
||||
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
||||
if (score > 0)
|
||||
{
|
||||
c.Score = score;
|
||||
if (score == titleMatch.Score)
|
||||
{
|
||||
c.TitleHighlightData = titleMatch.MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
c.SubTitleHighlightData = subTitleMatch.MatchData;
|
||||
}
|
||||
results.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user