@@ -25,7 +25,6 @@ import { IEditorOptions } from 'vs/platform/editor/common/editor';
2525import { Event , Emitter } from 'vs/base/common/event' ;
2626import { createStyleSheet , addStandardDisposableListener } from 'vs/base/browser/dom' ;
2727import { ScrollbarVisibility } from 'vs/base/common/scrollable' ;
28- import { FuzzyScore } from 'vs/base/common/filters' ;
2928import { InputBox , IInputOptions } from 'vs/base/browser/ui/inputbox/inputBox' ;
3029import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
3130import { TPromise } from 'vs/base/common/winjs.base' ;
@@ -559,7 +558,10 @@ export class TreeResourceNavigator extends Disposable {
559558
560559
561560export interface IHighlightingRenderer extends ITreeRenderer {
562- updateHighlights ( tree : ITree , element : any , pattern : string ) : FuzzyScore ;
561+ /**
562+ * Update hightlights and return the best matching element
563+ */
564+ updateHighlights ( tree : ITree , pattern : string ) : any ;
563565}
564566
565567export interface IHighlightingTreeConfiguration extends ITreeConfiguration {
@@ -671,27 +673,29 @@ export class HighlightingWorkbenchTree extends WorkbenchTree {
671673 super . layout ( isNaN ( height ) ? height : height - this . input . height , width ) ;
672674 }
673675
676+ private lastSelection : any [ ] ;
677+
674678 private updateHighlights ( pattern : string ) : void {
675- let nav = this . getNavigator ( undefined , false ) ;
676- let topScore : FuzzyScore ;
677- let topElement : any ;
678- while ( nav . next ( ) ) {
679- let element = nav . current ( ) ;
680- let score = this . renderer . updateHighlights ( this , element , pattern ) ;
681- if ( ! topScore || score && topScore [ 0 ] < score [ 0 ] ) {
682- topScore = score ;
683- topElement = element ;
684- }
685- this . refresh ( element ) . then ( undefined , onUnexpectedError ) ;
679+
680+ // remember old selection
681+ let defaultSelection : any [ ] ;
682+ if ( ! this . lastSelection && pattern ) {
683+ this . lastSelection = this . getSelection ( ) ;
684+ defaultSelection = [ ] ;
685+ } else if ( this . lastSelection && ! pattern ) {
686+ defaultSelection = this . lastSelection ;
687+ this . lastSelection = [ ] ;
686688 }
687- if ( topElement ) {
689+
690+ let topElement = this . renderer . updateHighlights ( this , pattern ) ;
691+ if ( topElement && pattern ) {
688692 this . reveal ( topElement ) . then ( _ => {
689- this . setFocus ( topElement ) ;
690693 this . setSelection ( [ topElement ] , this ) ;
694+ return this . refresh ( ) ;
691695 } , onUnexpectedError ) ;
692696 } else {
693- this . setSelection ( [ ] , this ) ;
694- this . setFocus ( undefined ) ;
697+ this . setSelection ( defaultSelection , this ) ;
698+ this . refresh ( ) . then ( undefined , onUnexpectedError ) ;
695699 }
696700 }
697701}
0 commit comments