Skip to content

Commit 3d79e4d

Browse files
committed
feat: show history and suggestions together
1 parent 3e514f8 commit 3d79e4d

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

CmdPalWebSearchShortcut/WebSearchShortcut/History/HistoryService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static string[] Get(string shortcutName)
3939
}
4040
}
4141

42+
public static string[] Search(string shortcutName, string searchText)
43+
{
44+
lock (_lock)
45+
{
46+
return [
47+
.. Get(shortcutName)
48+
.Where(query => query.StartsWith(searchText, StringComparison.OrdinalIgnoreCase))
49+
];
50+
}
51+
}
52+
4253
public static void Add(string shortcutName, string query)
4354
{
4455
lock (_lock)

CmdPalWebSearchShortcut/WebSearchShortcut/Pages/SearchWebPage.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace WebSearchShortcut;
1414

1515
internal sealed partial class SearchWebPage : DynamicListPage
1616
{
17+
private const int MaxHistoryDisplayCount = 3;
1718
private const int MaxDisplayCount = 100;
1819

1920
private readonly WebSearchShortcutDataEntry _shortcut;
@@ -97,12 +98,12 @@ public override async void UpdateSearchText(string oldSearch, string newSearch)
9798
{
9899
}
99100

101+
var historyItems = BuildHistoryItems(newSearch);
102+
100103
if (shouldOpenHomePage)
101104
{
102105
UpdateSuggestionItems([], currentEpoch);
103106

104-
var historyItems = BuildHistoryItems();
105-
106107
RenderItems([_openHomepageListItem, .. historyItems], currentEpoch);
107108

108109
return;
@@ -111,7 +112,7 @@ public override async void UpdateSearchText(string oldSearch, string newSearch)
111112
var primaryItems = BuildPrimaryItems(newSearch);
112113
var snapshotSuggestions = Volatile.Read(ref _suggestionItems);
113114

114-
RenderItems([.. primaryItems, .. snapshotSuggestions], currentEpoch);
115+
RenderItems([.. primaryItems, .. historyItems, .. snapshotSuggestions], currentEpoch);
115116

116117
if (!shouldFetchSuggestions)
117118
return;
@@ -143,7 +144,7 @@ public override async void UpdateSearchText(string oldSearch, string newSearch)
143144

144145
UpdateSuggestionItems(suggestionItems, currentEpoch);
145146

146-
RenderItems([.. primaryItems, .. suggestionItems], currentEpoch);
147+
RenderItems([.. primaryItems, .. historyItems, .. suggestionItems], currentEpoch);
147148
}
148149

149150
private void RenderItems(IListItem[] items, int currentUpdateSearchTextEpoch)
@@ -196,11 +197,11 @@ private ListItem[] BuildPrimaryItems(string searchText)
196197
];
197198
}
198199

199-
private ListItem[] BuildHistoryItems()
200+
private ListItem[] BuildHistoryItems(string searchText)
200201
{
201202
var historyQueries = HistoryService
202-
.Get(_shortcut.Name)
203-
.Take(MaxDisplayCount - 1);
203+
.Search(_shortcut.Name, searchText)
204+
.Take(string.IsNullOrEmpty(searchText) ? MaxDisplayCount : MaxHistoryDisplayCount);
204205

205206
return [
206207
.. historyQueries.Select(historyQuery => new ListItem(

0 commit comments

Comments
 (0)