Skip to content

Commit

Permalink
fix: hidden default item if match other item
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed Apr 25, 2024
1 parent 1b8395a commit 6ca2536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public List<Result> Query(Query query)
results.AddRange(SuggestionsCache);
}

if (WebSearchShortcutStorage.DefaultItem != null && item == null)
if (WebSearchShortcutStorage.DefaultItem != null && WebSearchShortcutStorage.GetRecord(tokens[0], true) == null)
{
results.Add(GetResultForSearch(WebSearchShortcutStorage.DefaultItem, args, query, true));
results.AddRange(SuggestionsCache);
Expand Down Expand Up @@ -206,7 +206,7 @@ public List<Result> Query(Query query, bool delayedExecution)
{
results = ProcessItem(item, tokens, query, results);
}
else if (item == null && defaultItem != null && !string.IsNullOrEmpty(defaultItem.SuggestionProvider))
else if (WebSearchShortcutStorage.GetRecord(tokens[0], true) == null && defaultItem != null && !string.IsNullOrEmpty(defaultItem.SuggestionProvider))
{
results = ProcessDefaultItem(defaultItem, tokens, query, results);
}
Expand Down
7 changes: 4 additions & 3 deletions Community.PowerToys.Run.Plugin.WebSearchShortcut/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public interface IWebSearchShortcutStorage
/// Gets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="includeNoPlaceholder"></param>
/// <returns>The record.</returns>
Item? GetRecord(string key);
Item? GetRecord(string key, bool includeNoPlaceholder = false);

/// <summary>
/// Loads file.
Expand Down Expand Up @@ -92,15 +93,15 @@ public IReadOnlyCollection<Item> GetRecords(string query) => Data.Values
).ToList().AsReadOnly();

/// <inheritdoc/>
public Item? GetRecord(string key)
public Item? GetRecord(string key, bool includeNoPlaceholder = false)
{
key = key.Trim();
return Data.Values
// .Where(x => x.IsDefault != true)
.FirstOrDefault(x =>
((x.Name?.Equals(key, StringComparison.InvariantCultureIgnoreCase) ?? false)
|| (x.Keyword?.Equals(key, StringComparison.InvariantCultureIgnoreCase) ?? false)
) && x.Url.Contains("%s"));
) && (includeNoPlaceholder || x.Url.Contains("%s")));
}

public Item? DefaultItem => Data.Values.FirstOrDefault(x => x?.IsDefault == true, null);
Expand Down

0 comments on commit 6ca2536

Please sign in to comment.