Skip to content

Commit 4e09d96

Browse files
committed
feat: show history and suggestions together
1 parent 3f48c67 commit 4e09d96

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;
@@ -98,12 +99,12 @@ public override async void UpdateSearchText(string oldSearch, string newSearch)
9899
{
99100
}
100101

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

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

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

115-
RenderItems([.. primaryItems, .. snapshotSuggestions], currentEpoch);
116+
RenderItems([.. primaryItems, .. historyItems, .. snapshotSuggestions], currentEpoch);
116117

117118
if (!shouldFetchSuggestions)
118119
return;
@@ -144,7 +145,7 @@ public override async void UpdateSearchText(string oldSearch, string newSearch)
144145

145146
UpdateSuggestionItems(suggestionItems, currentEpoch);
146147

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

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

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

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

0 commit comments

Comments
 (0)