提交 bf7e10ce 编写于 作者: S Sandeep Somavarapu

fix #8829

上级 0a91a54c
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import 'vs/css!./media/searchviewlet'; import 'vs/css!./media/searchviewlet';
import nls = require('vs/nls'); import nls = require('vs/nls');
import {TPromise, PPromise} from 'vs/base/common/winjs.base'; import {TPromise} from 'vs/base/common/winjs.base';
import {EditorType} from 'vs/editor/common/editorCommon'; import {EditorType} from 'vs/editor/common/editorCommon';
import {IDiffEditor} from 'vs/editor/browser/editorBrowser'; import {IDiffEditor} from 'vs/editor/browser/editorBrowser';
import lifecycle = require('vs/base/common/lifecycle'); import lifecycle = require('vs/base/common/lifecycle');
...@@ -64,7 +64,6 @@ export class SearchViewlet extends Viewlet { ...@@ -64,7 +64,6 @@ export class SearchViewlet extends Viewlet {
private isDisposed: boolean; private isDisposed: boolean;
private toDispose: lifecycle.IDisposable[]; private toDispose: lifecycle.IDisposable[];
private currentRequest: PPromise<ISearchComplete, ISearchProgressItem>;
private loading: boolean; private loading: boolean;
private queryBuilder: QueryBuilder; private queryBuilder: QueryBuilder;
private viewModel: SearchModel; private viewModel: SearchModel;
...@@ -257,7 +256,7 @@ export class SearchViewlet extends Viewlet { ...@@ -257,7 +256,7 @@ export class SearchViewlet extends Viewlet {
this.updateGlobalPatternExclusions(this.configurationService.getConfiguration<ISearchConfiguration>()); this.updateGlobalPatternExclusions(this.configurationService.getConfiguration<ISearchConfiguration>());
this.registerListeners(); this.toUnbind.push(this.viewModel.searchResult.onChange((event) => this.onSearchResultsChanged(event)));
return TPromise.as(null); return TPromise.as(null);
} }
...@@ -315,26 +314,30 @@ export class SearchViewlet extends Viewlet { ...@@ -315,26 +314,30 @@ export class SearchViewlet extends Viewlet {
this.storageService.store(SearchViewlet.SHOW_REPLACE_STORAGE_KEY, this.searchAndReplaceWidget.isReplaceShown(), StorageScope.WORKSPACE); this.storageService.store(SearchViewlet.SHOW_REPLACE_STORAGE_KEY, this.searchAndReplaceWidget.isReplaceShown(), StorageScope.WORKSPACE);
} }
private registerListeners(): void { private onSearchResultsChanged(event?: IChangeEvent): TPromise<any> {
this.toUnbind.push(this.viewModel.searchResult.onChange((event) => { return this.refreshTree(event).then(() => {
this.refreshTree(event);
this.searchWidget.setReplaceAllActionState(!this.viewModel.searchResult.isEmpty()); this.searchWidget.setReplaceAllActionState(!this.viewModel.searchResult.isEmpty());
})); });
} }
private refreshTree(event: IChangeEvent): void { private refreshTree(event?: IChangeEvent): TPromise<any> {
if (!event) {
return this.tree.refresh();
}
if (event.added || event.removed) { if (event.added || event.removed) {
this.tree.refresh(this.viewModel.searchResult); return this.tree.refresh(this.viewModel.searchResult).then(() => {
if (event.added) { if (event.added) {
event.elements.forEach(element => { event.elements.forEach(element => {
this.autoExpandFileMatch(element, true); this.autoExpandFileMatch(element, true);
}); });
} }
});
} else { } else {
if (event.elements.length === 1) { if (event.elements.length === 1) {
this.tree.refresh(event.elements[0]); return this.tree.refresh(event.elements[0]);
} else { } else {
this.tree.refresh(event.elements); return this.tree.refresh(event.elements);
} }
} }
} }
...@@ -526,22 +529,14 @@ export class SearchViewlet extends Viewlet { ...@@ -526,22 +529,14 @@ export class SearchViewlet extends Viewlet {
this.viewModel.searchResult.clear(); this.viewModel.searchResult.clear();
this.showEmptyStage(); this.showEmptyStage();
this.searchWidget.clear(); this.searchWidget.clear();
if (this.currentRequest) { this.viewModel.cancelSearch();
this.currentRequest.cancel();
this.currentRequest = null;
}
} }
public cancelSearch(): boolean { public cancelSearch(): boolean {
if (this.currentRequest) { if (this.viewModel.cancelSearch()) {
this.searchWidget.focus(); this.searchWidget.focus();
this.currentRequest.cancel();
this.currentRequest = null;
return true; return true;
} }
return false; return false;
} }
...@@ -697,6 +692,8 @@ export class SearchViewlet extends Viewlet { ...@@ -697,6 +692,8 @@ export class SearchViewlet extends Viewlet {
} }
private onQueryTriggered(query: ISearchQuery, excludePattern: string, includePattern: string): void { private onQueryTriggered(query: ISearchQuery, excludePattern: string, includePattern: string): void {
this.viewModel.cancelSearch();
// Progress total is 100% // Progress total is 100%
let progressTotal = 100; let progressTotal = 100;
let progressRunner = this.progressService.show(progressTotal); let progressRunner = this.progressService.show(progressTotal);
...@@ -733,10 +730,9 @@ export class SearchViewlet extends Viewlet { ...@@ -733,10 +730,9 @@ export class SearchViewlet extends Viewlet {
progressRunner.done(); progressRunner.done();
} }
this.onSearchResultsChanged().then(() => autoExpand(true));
this.viewModel.replaceText= this.searchWidget.getReplaceValue(); this.viewModel.replaceText= this.searchWidget.getReplaceValue();
autoExpand(true);
let hasResults = !this.viewModel.searchResult.isEmpty(); let hasResults = !this.viewModel.searchResult.isEmpty();
this.loading = false; this.loading = false;
...@@ -882,8 +878,7 @@ export class SearchViewlet extends Viewlet { ...@@ -882,8 +878,7 @@ export class SearchViewlet extends Viewlet {
this.searchWidget.setReplaceAllActionState(false); this.searchWidget.setReplaceAllActionState(false);
this.replaceService.disposeAllInputs(); this.replaceService.disposeAllInputs();
this.currentRequest = this.viewModel.search(query); this.viewModel.search(query).done(onComplete, onError, onProgress);
this.currentRequest.done(onComplete, onError, onProgress);
} }
private showEmptyStage(): void { private showEmptyStage(): void {
......
...@@ -438,7 +438,7 @@ export class SearchModel extends Disposable { ...@@ -438,7 +438,7 @@ export class SearchModel extends Disposable {
return this.isReplaceActive() && !!this.replaceText; return this.isReplaceActive() && !!this.replaceText;
} }
public search(query: ISearchQuery, silent: boolean= true): PPromise<ISearchComplete, ISearchProgressItem> { public search(query: ISearchQuery): PPromise<ISearchComplete, ISearchProgressItem> {
this.cancelSearch(); this.cancelSearch();
this.searchResult.clear(); this.searchResult.clear();
...@@ -450,21 +450,23 @@ export class SearchModel extends Disposable { ...@@ -450,21 +450,23 @@ export class SearchModel extends Disposable {
this.currentRequest = this.searchService.search(this._searchQuery); this.currentRequest = this.searchService.search(this._searchQuery);
this.currentRequest.then(value => this.onSearchCompleted(value), this.currentRequest.then(value => this.onSearchCompleted(value),
e => this.onSearchError(e, silent), e => this.onSearchError(e),
p => this.onSearchProgress(p, silent)); p => this.onSearchProgress(p));
return this.currentRequest; return this.currentRequest;
} }
private onSearchCompleted(completed: ISearchComplete): ISearchComplete { private onSearchCompleted(completed: ISearchComplete): ISearchComplete {
this.timerEvent.stop(); this.timerEvent.stop();
this._searchResult.add(completed.results);
this.telemetryService.publicLog('searchResultsShown', { count: this._searchResult.count(), fileCount: this._searchResult.fileCount() }); this.telemetryService.publicLog('searchResultsShown', { count: this._searchResult.count(), fileCount: this._searchResult.fileCount() });
this.doneTimer.stop(); this.doneTimer.stop();
if (completed) {
this._searchResult.add(completed.results, false);
}
return completed; return completed;
} }
private onSearchError(e: any, silent: boolean): void { private onSearchError(e: any): void {
if (errors.isPromiseCanceledError(e)) { if (errors.isPromiseCanceledError(e)) {
this.onSearchCompleted(null); this.onSearchCompleted(null);
} else { } else {
...@@ -473,18 +475,20 @@ export class SearchModel extends Disposable { ...@@ -473,18 +475,20 @@ export class SearchModel extends Disposable {
} }
} }
private onSearchProgress(p: ISearchProgressItem, silent: boolean): void { private onSearchProgress(p: ISearchProgressItem): void {
if (p.resource) { if (p.resource) {
this._searchResult.add([p], silent); this._searchResult.add([p], true);
this.progressTimer.stop(); this.progressTimer.stop();
} }
} }
public cancelSearch(): void{ public cancelSearch(): boolean {
if (this.currentRequest) { if (this.currentRequest) {
this.currentRequest.cancel(); this.currentRequest.cancel();
this.currentRequest = null; this.currentRequest = null;
return true;
} }
return false;
} }
public dispose(): void { public dispose(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册