44 *--------------------------------------------------------------------------------------------*/
55
66import 'vs/css!./media/anythingQuickAccess' ;
7- import { IQuickPickSeparator , IQuickInputButton , IKeyMods , quickPickItemScorerAccessor , QuickPickItemScorerAccessor , IQuickPick } from 'vs/platform/quickinput/common/quickInput' ;
8- import { IPickerQuickAccessItem , PickerQuickAccessProvider , TriggerAction , FastAndSlowPicksType } from 'vs/platform/quickinput/browser/pickerQuickAccess' ;
7+ import { IQuickInputButton , IKeyMods , quickPickItemScorerAccessor , QuickPickItemScorerAccessor , IQuickPick } from 'vs/platform/quickinput/common/quickInput' ;
8+ import { IPickerQuickAccessItem , PickerQuickAccessProvider , TriggerAction , FastAndSlowPicks , Picks } from 'vs/platform/quickinput/browser/pickerQuickAccess' ;
99import { prepareQuery , IPreparedQuery , compareItemsByScore , scoreItem , ScorerCache } from 'vs/base/common/fuzzyScorer' ;
1010import { IFileQueryBuilderOptions , QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder' ;
1111import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -88,7 +88,9 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
8888 lastOriginalFilter : string | undefined = undefined ;
8989 lastFilter : string | undefined = undefined ;
9090 lastRange : IRange | undefined = undefined ;
91+
9192 lastActiveGlobalPick : IAnythingQuickPickItem | undefined = undefined ;
93+ lastActiveEditorSymbolPick : IAnythingQuickPickItem | undefined = undefined ;
9294
9395 isQuickNavigating : boolean | undefined = undefined ;
9496
@@ -117,6 +119,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
117119 this . lastFilter = undefined ;
118120 this . lastRange = undefined ;
119121 this . lastActiveGlobalPick = undefined ;
122+ this . lastActiveEditorSymbolPick = undefined ;
120123 this . editorViewState = undefined ;
121124 }
122125
@@ -240,7 +243,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
240243 return toDisposable ( ( ) => this . clearDecorations ( activeEditorControl ) ) ;
241244 }
242245
243- protected getPicks ( originalFilter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem | IQuickPickSeparator > > | FastAndSlowPicksType < IAnythingQuickPickItem > | null {
246+ protected getPicks ( originalFilter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Picks < IAnythingQuickPickItem > > | FastAndSlowPicks < IAnythingQuickPickItem > | null {
244247
245248 // Find a suitable range from the pattern looking for ":", "#" or ","
246249 // unless we have the `@` editor symbol character inside the filter
@@ -269,16 +272,24 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
269272 this . pickState . lastOriginalFilter = originalFilter ;
270273 this . pickState . lastFilter = filter ;
271274
272- // Remember last active pick (unless editor symbol)
275+ // Remember last active pick (global or editor symbol)
273276 const activePick = this . pickState . picker ?. activeItems [ 0 ] ;
274- if ( activePick && ! isEditorSymbolQuickPickItem ( activePick ) ) {
275- this . pickState . lastActiveGlobalPick = activePick ;
277+ if ( activePick ) {
278+ if ( isEditorSymbolQuickPickItem ( activePick ) ) {
279+ // remember the editor symbol pick, but do not unset the
280+ // global pick as we can use it later to restore it when
281+ // the user narrows out of the editor symbol search
282+ this . pickState . lastActiveEditorSymbolPick = activePick ;
283+ } else {
284+ this . pickState . lastActiveGlobalPick = activePick ;
285+ this . pickState . lastActiveEditorSymbolPick = undefined ;
286+ }
276287 }
277288
278289 return this . doGetPicks ( filter , disposables , token ) ;
279290 }
280291
281- private doGetPicks ( filter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem | IQuickPickSeparator > > | FastAndSlowPicksType < IAnythingQuickPickItem > | null {
292+ private doGetPicks ( filter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Picks < IAnythingQuickPickItem > > | FastAndSlowPicks < IAnythingQuickPickItem > | null {
282293 const query = prepareQuery ( filter ) ;
283294
284295 // Return early if we have editor symbol picks. We support this by:
@@ -289,22 +300,32 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
289300 return editorSymbolPicks ;
290301 }
291302
303+ // If we have a known last active editor symbol pick, we try to restore
304+ // the last global pick to support the case of narrowing out from a
305+ // editor symbol search back into the global search
306+ let activeGlobalPick : IAnythingQuickPickItem | undefined = undefined ;
307+ if ( this . pickState . lastActiveEditorSymbolPick ) {
308+ activeGlobalPick = this . pickState . lastActiveGlobalPick ;
309+ }
310+
292311 // Otherwise return normally with history and file/symbol results
293312 const historyEditorPicks = this . getEditorHistoryPicks ( query ) ;
294313
295314 return {
296315
297316 // Fast picks: editor history
298- picks :
299- ( this . pickState . isQuickNavigating || historyEditorPicks . length === 0 ) ?
317+ picks : {
318+ items : ( this . pickState . isQuickNavigating || historyEditorPicks . length === 0 ) ?
300319 historyEditorPicks :
301320 [
302321 { type : 'separator' , label : localize ( 'recentlyOpenedSeparator' , "recently opened" ) } ,
303322 ...historyEditorPicks
304323 ] ,
324+ active : activeGlobalPick ? this . findPick ( historyEditorPicks , activeGlobalPick ) : undefined
325+ } ,
305326
306327 // Slow picks: files and symbols
307- additionalPicks : ( async ( ) : Promise < Array < IAnythingQuickPickItem | IQuickPickSeparator > > => {
328+ additionalPicks : ( async ( ) : Promise < Picks < IAnythingQuickPickItem > > => {
308329
309330 // Exclude any result that is already present in editor history
310331 const additionalPicksExcludes = new ResourceMap < boolean > ( ) ;
@@ -319,14 +340,27 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
319340 return [ ] ;
320341 }
321342
322- return additionalPicks . length > 0 ? [
323- { type : 'separator' , label : this . configuration . includeSymbols ? localize ( 'fileAndSymbolResultsSeparator' , "file and symbol results" ) : localize ( 'fileResultsSeparator' , "file results" ) } ,
324- ...additionalPicks
325- ] : [ ] ;
343+ return {
344+ items : additionalPicks . length > 0 ? [
345+ { type : 'separator' , label : this . configuration . includeSymbols ? localize ( 'fileAndSymbolResultsSeparator' , "file and symbol results" ) : localize ( 'fileResultsSeparator' , "file results" ) } ,
346+ ...additionalPicks
347+ ] : [ ] ,
348+ active : activeGlobalPick ? this . findPick ( additionalPicks , activeGlobalPick ) : undefined
349+ } ;
326350 } ) ( )
327351 } ;
328352 }
329353
354+ private findPick ( picks : IAnythingQuickPickItem [ ] , candidate : IAnythingQuickPickItem ) : IAnythingQuickPickItem | undefined {
355+ for ( const pick of picks ) {
356+ if ( isEqual ( pick . resource , candidate . resource ) ) {
357+ return pick ;
358+ }
359+ }
360+
361+ return undefined ;
362+ }
363+
330364 private async getAdditionalPicks ( query : IPreparedQuery , excludes : ResourceMap < boolean > , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem > > {
331365
332366 // Resolve file and symbol picks (if enabled)
@@ -636,7 +670,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
636670
637671 private readonly editorSymbolsQuickAccess = this . instantiationService . createInstance ( GotoSymbolQuickAccessProvider ) ;
638672
639- private getEditorSymbolPicks ( query : IPreparedQuery , disposables : DisposableStore , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem | IQuickPickSeparator > > | null {
673+ private getEditorSymbolPicks ( query : IPreparedQuery , disposables : DisposableStore , token : CancellationToken ) : Promise < Picks < IAnythingQuickPickItem > > | null {
640674 const filter = query . original . split ( GotoSymbolQuickAccessProvider . PREFIX ) [ 1 ] ?. trim ( ) ;
641675 if ( typeof filter !== 'string' ) {
642676 return null ; // we need to be searched for editor symbols via `@`
@@ -655,7 +689,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
655689 return this . doGetEditorSymbolPicks ( activeGlobalPick , activeGlobalResource , filter , disposables , token ) ;
656690 }
657691
658- private async doGetEditorSymbolPicks ( activeGlobalPick : IAnythingQuickPickItem , activeGlobalResource : URI , filter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem | IQuickPickSeparator > > {
692+ private async doGetEditorSymbolPicks ( activeGlobalPick : IAnythingQuickPickItem , activeGlobalResource : URI , filter : string , disposables : DisposableStore , token : CancellationToken ) : Promise < Picks < IAnythingQuickPickItem > > {
659693
660694 // Bring the editor to front to review symbols to go to
661695 try {
0 commit comments