@@ -56,6 +56,7 @@ export class SettingsEditor2 extends BaseEditor {
5656 private delayedFilterLogging : Delayer < void > ;
5757 private localSearchDelayer : Delayer < void > ;
5858 private remoteSearchThrottle : ThrottledDelayer < void > ;
59+ private searchInProgress : TPromise < void > ;
5960
6061 private pendingSettingModifiedReport : { key : string , value : any } ;
6162
@@ -424,14 +425,18 @@ export class SettingsEditor2 extends BaseEditor {
424425
425426 private triggerSearch ( query : string ) : TPromise < void > {
426427 if ( query ) {
427- return TPromise . join ( [
428+ return this . searchInProgress = TPromise . join ( [
428429 this . localSearchDelayer . trigger ( ( ) => this . localFilterPreferences ( query ) ) ,
429430 this . remoteSearchThrottle . trigger ( ( ) => this . remoteSearchPreferences ( query ) , 500 )
430- ] ) as TPromise ;
431+ ] ) . then ( ( ) => {
432+ this . searchInProgress = null ;
433+ } ) ;
431434 } else {
432- // When clearing the input, update immediately to clear it
433435 this . localSearchDelayer . cancel ( ) ;
434436 this . remoteSearchThrottle . cancel ( ) ;
437+ if ( this . searchInProgress && this . searchInProgress . cancel ) {
438+ this . searchInProgress . cancel ( ) ;
439+ }
435440
436441 this . searchResultModel = null ;
437442 this . settingsTree . setInput ( this . defaultSettingsEditorModel ) ;
@@ -495,15 +500,25 @@ export class SettingsEditor2 extends BaseEditor {
495500 private filterOrSearchPreferences ( query : string , type : SearchResultIdx , searchProvider : ISearchProvider ) : TPromise < void > {
496501 const filterPs : TPromise < ISearchResult > [ ] = [ this . _filterOrSearchPreferencesModel ( query , this . defaultSettingsEditorModel , searchProvider ) ] ;
497502
498- return TPromise . join ( filterPs ) . then ( results => {
499- const [ result ] = results ;
500- if ( ! this . searchResultModel ) {
501- this . searchResultModel = new SearchResultModel ( ) ;
502- this . settingsTree . setInput ( this . searchResultModel ) ;
503- }
503+ let isCanceled = false ;
504+ return new TPromise ( resolve => {
505+ return TPromise . join ( filterPs ) . then ( results => {
506+ if ( isCanceled ) {
507+ // Handle cancellation like this because cancellation is lost inside the search provider due to async/await
508+ return null ;
509+ }
510+
511+ const [ result ] = results ;
512+ if ( ! this . searchResultModel ) {
513+ this . searchResultModel = new SearchResultModel ( ) ;
514+ this . settingsTree . setInput ( this . searchResultModel ) ;
515+ }
504516
505- this . searchResultModel . setResult ( type , result ) ;
506- return this . refreshTreeAndMaintainFocus ( ) ;
517+ this . searchResultModel . setResult ( type , result ) ;
518+ resolve ( this . refreshTreeAndMaintainFocus ( ) ) ;
519+ } ) ;
520+ } , ( ) => {
521+ isCanceled = true ;
507522 } ) ;
508523 }
509524
0 commit comments