mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
To remove the condition that space is needed after the Action keyword (#6003)
* Returning individual queries for each plugin * Changed cancellation token from Query type to directly using the rawQuery * Changed the way we get the plugins for which we execute the query * updated UpdateResultView to take a string instead of query * Changed the way we set a query for each plugin * removed todo comment * global plugins are added as a part of the query builder * Fix for plugin.json of Folder plugin being copied into the shell plugin * >,< and : are not allowed in file paths and indexer creates a query which searches compares if a file name is greater than or lesser than the query * Reformatted the regex * catching the exception * fixed existing tests * modified it so that it works with action keyword as well as action keywords * Added unit tests for non global plugins * fixed test * add back whitespace that was removed by mistake * fix regex * modified the cold start query * remove extra condition * terms being modified as expected * used key value pairs to iterate through the dictionary * renamed variable * added check for an empty dictionary * remove : because it may appear in the file path * fix some whitespace warnings that were being treated as errors
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
public static class QueryBuilder
|
||||
{
|
||||
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
|
||||
public static Dictionary<PluginPair, Query> Build(ref string text, Dictionary<string, PluginPair> nonGlobalPlugins)
|
||||
{
|
||||
// replace multiple white spaces with one white space
|
||||
var terms = text.Split(new[] { Query.TermSeparator }, StringSplitOptions.RemoveEmptyEntries);
|
||||
@@ -20,32 +20,54 @@ namespace Wox.Core.Plugin
|
||||
return null;
|
||||
}
|
||||
|
||||
// This Dictionary contains the corresponding query for each plugin
|
||||
Dictionary<PluginPair, Query> pluginQueryPair = new Dictionary<PluginPair, Query>();
|
||||
|
||||
var rawQuery = string.Join(Query.TermSeparator, terms);
|
||||
string actionKeyword, search;
|
||||
|
||||
// This is the query on removing extra spaces which would be executed by global Plugins
|
||||
text = rawQuery;
|
||||
|
||||
string possibleActionKeyword = terms[0];
|
||||
List<string> actionParameters;
|
||||
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
|
||||
{ // use non global plugin for query
|
||||
actionKeyword = possibleActionKeyword;
|
||||
actionParameters = terms.Skip(1).ToList();
|
||||
search = actionParameters.Count > 0 ? rawQuery.Substring(actionKeyword.Length + 1) : string.Empty;
|
||||
}
|
||||
else
|
||||
{ // non action keyword
|
||||
actionKeyword = string.Empty;
|
||||
actionParameters = terms.ToList();
|
||||
search = rawQuery;
|
||||
}
|
||||
|
||||
var query = new Query
|
||||
foreach (string pluginActionKeyword in nonGlobalPlugins.Keys)
|
||||
{
|
||||
Terms = terms,
|
||||
RawQuery = rawQuery,
|
||||
ActionKeyword = actionKeyword,
|
||||
Search = search,
|
||||
};
|
||||
if (possibleActionKeyword.StartsWith(pluginActionKeyword))
|
||||
{
|
||||
if (nonGlobalPlugins.TryGetValue(pluginActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
|
||||
{
|
||||
// The search string is the raw query excluding the action keyword
|
||||
string search = rawQuery.Substring(pluginActionKeyword.Length).Trim();
|
||||
|
||||
return query;
|
||||
// To set the terms of the query after removing the action keyword
|
||||
if (possibleActionKeyword.Length > pluginActionKeyword.Length)
|
||||
{
|
||||
// If the first term contains the action keyword, then set the remaining string to be the first term
|
||||
terms[0] = possibleActionKeyword.Substring(pluginActionKeyword.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the first term is the action keyword, then skip it.
|
||||
terms = terms.Skip(1).ToArray();
|
||||
}
|
||||
|
||||
// A new query is constructed for each plugin as they have different action keywords
|
||||
var query = new Query(rawQuery, search, terms, pluginActionKeyword);
|
||||
|
||||
pluginQueryPair.TryAdd(pluginPair, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var globalplugins = PluginManager.GlobalPlugins;
|
||||
|
||||
foreach (PluginPair globalPlugin in PluginManager.GlobalPlugins)
|
||||
{
|
||||
var query = new Query(rawQuery, rawQuery, terms, string.Empty);
|
||||
pluginQueryPair.Add(globalPlugin, query);
|
||||
}
|
||||
|
||||
return pluginQueryPair;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user