@@ -69,32 +69,35 @@ export const handle_show_history_quick_pick = async (
6969 list : 'recents' | 'pinned' ,
7070 is_pinned : boolean ,
7171 pinned_index ?: number ,
72- total_pinned ?: number
72+ total_pinned ?: number ,
73+ is_searching ?: boolean
7374 ) : vscode . QuickPickItem => ( {
7475 label : text ,
7576 buttons : [
7677 ...( list == 'pinned' &&
7778 pinned_index !== undefined &&
7879 total_pinned !== undefined &&
7980 total_pinned > 1
80- ? [
81- ...( pinned_index > 0
82- ? [
83- {
84- iconPath : new vscode . ThemeIcon ( 'chevron-up' ) ,
85- tooltip : 'Move up'
86- }
87- ]
88- : [ ] ) ,
89- ...( pinned_index < total_pinned - 1
90- ? [
91- {
92- iconPath : new vscode . ThemeIcon ( 'chevron-down' ) ,
93- tooltip : 'Move down'
94- }
95- ]
96- : [ ] )
97- ]
81+ ? is_searching
82+ ? [ ]
83+ : [
84+ ...( pinned_index > 0
85+ ? [
86+ {
87+ iconPath : new vscode . ThemeIcon ( 'chevron-up' ) ,
88+ tooltip : 'Move up'
89+ }
90+ ]
91+ : [ ] ) ,
92+ ...( pinned_index < total_pinned - 1
93+ ? [
94+ {
95+ iconPath : new vscode . ThemeIcon ( 'chevron-down' ) ,
96+ tooltip : 'Move down'
97+ }
98+ ]
99+ : [ ] )
100+ ]
98101 : [ ] ) ,
99102 ...( ! is_pinned
100103 ? [
@@ -115,6 +118,7 @@ export const handle_show_history_quick_pick = async (
115118 } )
116119
117120 const items : vscode . QuickPickItem [ ] = [ ]
121+ let current_search_value = ''
118122
119123 if ( pinned_history . length > 0 ) {
120124 items . push ( {
@@ -146,16 +150,19 @@ export const handle_show_history_quick_pick = async (
146150
147151 quick_pick . items = items
148152
149- // Set the active item to the first recent item (not separator)
150153 if ( history . length > 0 ) {
151154 const firstRecentItemIndex = items . findIndex ( ( item , index ) => {
152- // Find the first item after the "recent" separator that's not a separator itself
153- const recentSeparatorIndex = items . findIndex ( i => i . label === 'recent' && i . kind === vscode . QuickPickItemKind . Separator )
154- return recentSeparatorIndex !== - 1 &&
155- index > recentSeparatorIndex &&
156- item . kind !== vscode . QuickPickItemKind . Separator
155+ const recentSeparatorIndex = items . findIndex (
156+ ( i ) =>
157+ i . label === 'recent' && i . kind === vscode . QuickPickItemKind . Separator
158+ )
159+ return (
160+ recentSeparatorIndex != - 1 &&
161+ index > recentSeparatorIndex &&
162+ item . kind !== vscode . QuickPickItemKind . Separator
163+ )
157164 } )
158- if ( firstRecentItemIndex !== - 1 ) {
165+ if ( firstRecentItemIndex != - 1 ) {
159166 quick_pick . activeItems = [ items [ firstRecentItemIndex ] ]
160167 }
161168 }
@@ -208,11 +215,9 @@ export const handle_show_history_quick_pick = async (
208215 const button_tooltip = e . button . tooltip
209216 const item_text = item_to_handle . label
210217
211- // Handle chevron up/down for pinned items
212- if ( button_tooltip === 'Move up' ) {
218+ if ( button_tooltip == 'Move up' ) {
213219 const current_index = pinned_history . indexOf ( item_text )
214220 if ( current_index > 0 ) {
215- // Swap with the item above
216221 const temp = pinned_history [ current_index - 1 ]
217222 pinned_history [ current_index - 1 ] = pinned_history [ current_index ]
218223 pinned_history [ current_index ] = temp
@@ -222,10 +227,9 @@ export const handle_show_history_quick_pick = async (
222227 pinned_history
223228 )
224229 }
225- } else if ( button_tooltip === 'Move down' ) {
230+ } else if ( button_tooltip == 'Move down' ) {
226231 const current_index = pinned_history . indexOf ( item_text )
227232 if ( current_index < pinned_history . length - 1 ) {
228- // Swap with the item below
229233 const temp = pinned_history [ current_index + 1 ]
230234 pinned_history [ current_index + 1 ] = pinned_history [ current_index ]
231235 pinned_history [ current_index ] = temp
@@ -235,36 +239,32 @@ export const handle_show_history_quick_pick = async (
235239 pinned_history
236240 )
237241 }
238- } else if ( button_tooltip === 'Add to Pinned Prompts' ) {
239- // Add item to pinned history if not already there
242+ } else if ( button_tooltip == 'Add to Pinned Prompts' ) {
240243 if ( ! pinned_history . includes ( item_text ) ) {
241244 pinned_history . push ( item_text )
242245 await provider . context . workspaceState . update (
243246 pinned_history_key ,
244247 pinned_history
245248 )
246249 }
247- } else if ( button_tooltip === 'Remove from Pinned Prompts' ) {
248- // Remove from pinned history
250+ } else if ( button_tooltip == 'Remove from Pinned Prompts' ) {
249251 const index = pinned_history . indexOf ( item_text )
250- if ( index !== - 1 ) {
252+ if ( index != - 1 ) {
251253 pinned_history . splice ( index , 1 )
252254 await provider . context . workspaceState . update (
253255 pinned_history_key ,
254256 pinned_history
255257 )
256258 }
257- } else if ( button_tooltip === 'Remove from Recent Prompts' ) {
258- // Remove from recent history
259+ } else if ( button_tooltip == 'Remove from Recent Prompts' ) {
259260 const index = history . indexOf ( item_text )
260- if ( index !== - 1 ) {
261+ if ( index != - 1 ) {
261262 history . splice ( index , 1 )
262263 await provider . context . workspaceState . update ( history_key , history )
263264 }
264265 }
265266
266- // Check if we should close the quick pick if no items remain
267- if ( history . length === 0 && pinned_history . length === 0 ) {
267+ if ( history . length == 0 && pinned_history . length == 0 ) {
268268 quick_pick . hide ( )
269269 return
270270 }
@@ -283,7 +283,8 @@ export const handle_show_history_quick_pick = async (
283283 'pinned' ,
284284 true ,
285285 index ,
286- pinned_history . length
286+ pinned_history . length ,
287+ ! ! current_search_value
287288 )
288289 )
289290 )
@@ -296,14 +297,49 @@ export const handle_show_history_quick_pick = async (
296297 } )
297298 updated_items . push (
298299 ...history . map ( ( item ) =>
299- to_quick_pick_item ( item , 'recents' , pinned_history . includes ( item ) )
300+ to_quick_pick_item (
301+ item ,
302+ 'recents' ,
303+ pinned_history . includes ( item ) ,
304+ undefined
305+ )
300306 )
301307 )
302308 }
303309
304310 quick_pick . items = updated_items
305311 handle_get_history ( provider )
306312 } ) ,
313+ quick_pick . onDidChangeValue ( ( ) => {
314+ if ( quick_pick . value == current_search_value ) return
315+ current_search_value = quick_pick . value
316+ const is_searching = current_search_value . length > 0
317+
318+ const new_items : vscode . QuickPickItem [ ] = [ ]
319+ if ( pinned_history . length > 0 ) {
320+ new_items . push ( {
321+ label : 'pinned' ,
322+ kind : vscode . QuickPickItemKind . Separator
323+ } )
324+ new_items . push (
325+ ...pinned_history . map ( ( item , index ) =>
326+ to_quick_pick_item (
327+ item ,
328+ 'pinned' ,
329+ true ,
330+ index ,
331+ pinned_history . length ,
332+ is_searching
333+ )
334+ )
335+ )
336+ }
337+
338+ const recent_items = quick_pick . items . filter (
339+ ( i ) => ( i as { list ?: string } ) . list == 'recents'
340+ )
341+ quick_pick . items = [ ...new_items , ...recent_items ]
342+ } ) ,
307343 quick_pick . onDidHide ( ( ) => {
308344 disposables . forEach ( ( d ) => d . dispose ( ) )
309345 } )
0 commit comments