Skip to content

Commit 592f60a

Browse files
committed
Code cleanup
1 parent 24d212f commit 592f60a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,26 @@ public int GetHashCode(Result obj)
4848
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
4949
{
5050
var results = new HashSet<Result>(PathEqualityComparator.Instance);
51-
var keywordStr = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword;
52-
bool isPathSearch = query.Search.IsLocationPathString()
53-
|| EnvironmentVariables.IsEnvironmentVariableSearch(query.Search)
54-
|| EnvironmentVariables.HasEnvironmentVar(query.Search);
51+
var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword;
52+
var isPathSearch = query.Search.IsLocationPathString()
53+
|| EnvironmentVariables.IsEnvironmentVariableSearch(query.Search)
54+
|| EnvironmentVariables.HasEnvironmentVar(query.Search);
5555

56-
var activeActionKeyword = Settings.GetActiveActionKeyword(keywordStr);
56+
// If action keyword is enabled and matched, get the active action keyword.
57+
var activeActionKeyword = Settings.GetActiveActionKeyword(keyword);
5758

59+
// No action keyword matched - plugin should not handle this query, return empty results.
5860
if (activeActionKeyword == null && !isPathSearch)
5961
{
6062
return [];
6163
}
6264

65+
// If no action keyword matched but the query is a path search, set active action keyword to path search.
6366
if (activeActionKeyword == null && isPathSearch) activeActionKeyword = ActionKeyword.PathSearchActionKeyword;
6467

6568
// This allows the user to type the below action keywords and see/search the list of quick folder links
66-
6769
if (string.IsNullOrEmpty(query.Search)
68-
&& activeActionKeyword!.Equals(ActionKeyword.QuickAccessActionKeyword))
70+
&& activeActionKeyword.Equals(ActionKeyword.QuickAccessActionKeyword))
6971
{
7072
return QuickAccess.AccessLinkListAll(query, Settings.QuickAccessLinks);
7173
}
@@ -74,11 +76,12 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
7476

7577
string engineName;
7678

77-
switch (activeActionKeyword!.Equals(ActionKeyword.PathSearchActionKeyword))
79+
switch (activeActionKeyword.Equals(ActionKeyword.PathSearchActionKeyword))
7880
{
7981
case true:
8082
results.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
8183
return [.. results];
84+
8285
case false
8386
// Intentionally require enabling of Everything's content search due to its slowness
8487
when activeActionKeyword.Equals(ActionKeyword.FileContentSearchActionKeyword):
@@ -93,7 +96,6 @@ when activeActionKeyword.Equals(ActionKeyword.FileContentSearchActionKeyword):
9396
when activeActionKeyword.Equals(ActionKeyword.QuickAccessActionKeyword):
9497
return QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks);
9598

96-
9799
default:
98100
searchResults = Settings.IndexProvider.SearchAsync(query.Search, token);
99101
engineName = Enum.GetName(Settings.IndexSearchEngine);
@@ -255,15 +257,20 @@ private bool IsExcludedFile(SearchResult result)
255257

256258
private bool ShouldSkip(ActionKeyword actionKeywordActive, SearchResult search)
257259
{
260+
// Is excluded file type
258261
if (search.Type == ResultType.File && IsExcludedFile(search))
262+
{
259263
return true;
264+
}
260265

266+
// Action keyword specific filtering for folders
261267
if (actionKeywordActive.Equals(ActionKeyword.FolderSearchActionKeyword)
262268
&& search.Type != ResultType.Folder)
263269
{
264270
return true;
265271
}
266272

273+
// Action keyword specific filtering for files
267274
if (actionKeywordActive.Equals(ActionKeyword.FileSearchActionKeyword)
268275
&& search.Type != ResultType.File)
269276
{
@@ -278,7 +285,10 @@ private void MergeQuickAccessInResultsIfQueryMatch(HashSet<Result> results, Quer
278285
if (activeActionKeyword != null
279286
&& activeActionKeyword != ActionKeyword.QuickAccessActionKeyword
280287
&& Settings.ExcludeQuickAccessFromActionKeywords)
288+
{
281289
return;
290+
}
291+
282292
var quickAccessMatched = QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks);
283293
if (quickAccessMatched != null && quickAccessMatched.Count > 0) results.UnionWith(quickAccessMatched);
284294
}

0 commit comments

Comments
 (0)