Skip to content

Commit 554bc08

Browse files
authored
Merge pull request #348 from Flow-Launcher/fix_duplicate_entry_quickaccess
Remove duplicate entry
2 parents dddeeab + abb11b2 commit 554bc08

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
1+
using Flow.Launcher.Infrastructure.UserSettings;
2+
using Flow.Launcher.Plugin;
23
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
44
using System.Collections.Specialized;
55
using System.Linq;
66
using System.Threading;
7-
using System.Threading.Tasks;
87
using System.Windows;
98
using System.Windows.Controls;
109
using System.Windows.Data;
1110
using System.Windows.Documents;
12-
using Flow.Launcher.Infrastructure.UserSettings;
13-
using Flow.Launcher.Plugin;
1411

1512
namespace Flow.Launcher.ViewModel
1613
{

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ public SearchManager(Settings settings, PluginInitContext context)
2222
this.settings = settings;
2323
}
2424

25+
private class PathEqualityComparator : IEqualityComparer<Result>
26+
{
27+
private static PathEqualityComparator instance;
28+
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();
29+
public bool Equals(Result x, Result y)
30+
{
31+
return x.SubTitle == y.SubTitle;
32+
}
33+
34+
public int GetHashCode(Result obj)
35+
{
36+
return obj.SubTitle.GetHashCode();
37+
}
38+
}
39+
2540
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
2641
{
27-
var results = new List<Result>();
42+
var results = new HashSet<Result>(PathEqualityComparator.Instance);
2843

2944
var querySearch = query.Search;
3045

@@ -38,7 +53,7 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
3853
var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks);
3954

4055
if (quickaccessLinks.Count > 0)
41-
results.AddRange(quickaccessLinks);
56+
results.UnionWith(quickaccessLinks);
4257

4358
var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);
4459

@@ -50,9 +65,9 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
5065

5166
if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath)
5267
{
53-
results.AddRange(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
68+
results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
5469

55-
return results;
70+
return results.ToList();
5671
}
5772

5873
var locationPath = querySearch;
@@ -62,7 +77,7 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
6277

6378
// Check that actual location exists, otherwise directory search will throw directory not found exception
6479
if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath)))
65-
return results;
80+
return results.ToList();
6681

6782
var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath);
6883

@@ -79,9 +94,9 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
7994

8095
token.ThrowIfCancellationRequested();
8196

82-
results.AddRange(directoryResult);
97+
results.UnionWith(directoryResult);
8398

84-
return results;
99+
return results.ToList();
85100
}
86101

87102
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token)

Plugins/Flow.Launcher.Plugin.Explorer/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"Name": "Explorer",
88
"Description": "Search and manage files and folders. Explorer utilises Windows Index Search",
99
"Author": "Jeremy Wu",
10-
"Version": "1.7.0",
10+
"Version": "1.7.1",
1111
"Language": "csharp",
1212
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
1313
"ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll",

0 commit comments

Comments
 (0)