[PTRun]Don't show results from other plugins when using keyword (#19206)

This commit is contained in:
Davide Giacometti
2022-07-15 11:38:11 +02:00
committed by GitHub
parent 8e2570033c
commit 996a235e12
9 changed files with 53 additions and 35 deletions

View File

@@ -136,10 +136,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
});
}
if (query.ActionKeyword == string.Empty || (query.ActionKeyword != string.Empty && query.Search != string.Empty))
{
results = results.Where(a => a.Title.ToLowerInvariant().Contains(query.Search.ToLowerInvariant())).ToList();
}
results.ForEach(x =>
{

View File

@@ -60,8 +60,8 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
var results = new List<Result>();
// empty non-global query:
if (!AreResultsGlobal() && query.ActionKeyword == query.RawQuery)
// empty query
if (string.IsNullOrEmpty(query.Search))
{
string arguments = "? ";
results.Add(new Result
@@ -84,8 +84,7 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
});
return results;
}
if (!string.IsNullOrEmpty(query.Search))
else
{
string searchTerm = query.Search;

View File

@@ -46,8 +46,7 @@ namespace Microsoft.Plugin.Uri
{
var results = new List<Result>();
if (IsActivationKeyword(query)
&& BrowserInfo.IsDefaultBrowserSet)
if (string.IsNullOrWhiteSpace(query?.Search) && BrowserInfo.IsDefaultBrowserSet)
{
results.Add(new Result
{
@@ -104,12 +103,6 @@ namespace Microsoft.Plugin.Uri
return results;
}
private static bool IsActivationKeyword(Query query)
{
return !string.IsNullOrEmpty(query?.ActionKeyword)
&& query?.ActionKeyword == query?.RawQuery;
}
public void Init(PluginInitContext context)
{
Context = context ?? throw new ArgumentNullException(nameof(context));

View File

@@ -5,7 +5,6 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Wox.Infrastructure;
@@ -37,7 +36,6 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
[DataRow("now", 3)]
[DataRow("current", 3)]
[DataRow("year", 0)]
[DataRow("", 0)]
[DataRow("time::10:10:10", 0)]
[DataRow("date::10/10/10", 0)]
public void CountWithoutPluginKeyword(string typedString, int expectedResultCount)

View File

@@ -42,12 +42,6 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
bool isEmptySearchInput = string.IsNullOrEmpty(query.Search);
string searchTerm = query.Search;
// Empty search without keyword => return no results
if (!isKeywordSearch && isEmptySearchInput)
{
return results;
}
// Conjunction search without keyword => return no results
// (This improves the results on global queries.)
if (!isKeywordSearch && _conjunctionList.Any(x => x.Equals(searchTerm, StringComparison.CurrentCultureIgnoreCase)))

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// 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.
@@ -70,7 +70,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
// Action keyword only or search query match
int score = StringMatcher.FuzzySearch(search, profile.Name).Score;
if ((!string.IsNullOrWhiteSpace(query.ActionKeyword) && string.IsNullOrWhiteSpace(search)) || score > 0)
if (string.IsNullOrWhiteSpace(search) || score > 0)
{
result.Add(new Result
{

View File

@@ -175,6 +175,11 @@ namespace PowerLauncher.Plugin
return new List<Result>();
}
if (string.IsNullOrEmpty(query.ActionKeyword) && string.IsNullOrWhiteSpace(query.Search))
{
return new List<Result>();
}
try
{
List<Result> results = null;

View File

@@ -1,9 +1,8 @@
// Copyright (c) Microsoft Corporation
// 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.Linq;
using Mono.Collections.Generic;
@@ -58,7 +57,7 @@ namespace Wox.Plugin
{
if (_search == null)
{
_search = RawQuery.Substring(ActionKeyword.Length).Trim();
_search = RawQuery.Substring(ActionKeyword?.Length ?? 0).Trim();
}
return _search;

View File

@@ -17,12 +17,6 @@ namespace Wox.Test
[DataRow(">", "dummyQueryText", "dummyTitle", "> dummyQueryText")]
[DataRow(">", null, "dummyTitle", "> dummyTitle")]
[DataRow(">", "", "dummyTitle", "> dummyTitle")]
[DataRow("", "dummyQueryText", "dummyTitle", "dummyQueryText")]
[DataRow("", null, "dummyTitle", "dummyTitle")]
[DataRow("", "", "dummyTitle", "dummyTitle")]
[DataRow(null, "dummyQueryText", "dummyTitle", "dummyQueryText")]
[DataRow(null, null, "dummyTitle", "dummyTitle")]
[DataRow(null, "", "dummyTitle", "dummyTitle")]
public void QueryForPluginSetsActionKeywordWhenQueryTextDisplayIsEmpty(string actionKeyword, string queryTextDisplay, string title, string expectedResult)
{
// Arrange
@@ -58,5 +52,44 @@ namespace Wox.Test
// Assert
Assert.AreEqual(expectedResult, queryOutput[0].QueryTextDisplay);
}
[DataTestMethod]
[DataRow("", true)]
[DataRow(null, true)]
[DataRow(">", false)]
public void QueryDefaultResultsForPlugin(string actionKeyword, bool emptyResults)
{
// Arrange
var query = new Query(string.Empty, actionKeyword);
var metadata = new PluginMetadata
{
ID = "dummyName",
IcoPathDark = "dummyIcoPath",
IcoPathLight = "dummyIcoPath",
ExecuteFileName = "dummyExecuteFileName",
PluginDirectory = "dummyPluginDirectory",
ActionKeyword = ">",
IsGlobal = true,
};
var result = new Result()
{
QueryTextDisplay = "dummyQueryText",
Title = "dummyTitle",
};
var results = new List<Result>() { result };
var pluginMock = new Mock<IPlugin>();
pluginMock.Setup(r => r.Query(query)).Returns(results);
var pluginPair = new PluginPair(metadata)
{
Plugin = pluginMock.Object,
IsPluginInitialized = true,
};
// Act
var queryOutput = PluginManager.QueryForPlugin(pluginPair, query);
// Assert
Assert.AreEqual(queryOutput.Count == 0, emptyResults);
}
}
}