Skip to content

Commit

Permalink
Merge pull request #65143 from Microsoft/roblou/fixSearchCancel
Browse files Browse the repository at this point in the history
Fix #65084
  • Loading branch information
roblourens committed Dec 17, 2018
2 parents 8b7c775 + ae30d20 commit 58177b4
Showing 1 changed file with 80 additions and 69 deletions.
149 changes: 80 additions & 69 deletions src/vs/workbench/parts/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {

private searchWithoutFolderMessageElement: HTMLElement;

private currentSearchQ = Promise.resolve<void>();

constructor(
@IPartService partService: IPartService,
@ITelemetryService telemetryService: ITelemetryService,
Expand Down Expand Up @@ -1130,6 +1132,12 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {

this.viewModel.cancelSearch();

this.currentSearchQ = this.currentSearchQ
.then(() => this.doSearch(query, options, excludePatternText, includePatternText))
.then(() => { }, () => { });
}

private doSearch(query: ITextQuery, options: ITextQueryBuilderOptions, excludePatternText: string, includePatternText: string): Thenable<void> {
// Progress total is 100.0% for more progress bar granularity
let progressTotal = 1000;
let progressWorked = 0;
Expand Down Expand Up @@ -1160,7 +1168,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}

// Do final render, then expand if just 1 file with less than 50 matches
this.onSearchResultsChanged().then(() => {
return this.onSearchResultsChanged().then(() => {
if (this.viewModel.searchResult.count() === 1) {
const onlyMatch = this.viewModel.searchResult.matches()[0];
if (onlyMatch.count() < 50) {
Expand All @@ -1169,90 +1177,90 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}

return null;
});

this.viewModel.replaceString = this.searchWidget.getReplaceValue();

let hasResults = !this.viewModel.searchResult.isEmpty();
}).then(() => {
this.viewModel.replaceString = this.searchWidget.getReplaceValue();

this.searchSubmitted = true;
this.updateActions();
let hasResults = !this.viewModel.searchResult.isEmpty();

if (completed && completed.limitHit) {
this.searchWidget.searchInput.showMessage({
content: nls.localize('searchMaxResultsWarning', "The result set only contains a subset of all matches. Please be more specific in your search to narrow down the results."),
type: MessageType.WARNING
});
}
this.searchSubmitted = true;
this.updateActions();

if (!hasResults) {
let hasExcludes = !!excludePatternText;
let hasIncludes = !!includePatternText;
let message: string;

if (!completed) {
message = nls.localize('searchCanceled', "Search was canceled before any results could be found - ");
} else if (hasIncludes && hasExcludes) {
message = nls.localize('noResultsIncludesExcludes', "No results found in '{0}' excluding '{1}' - ", includePatternText, excludePatternText);
} else if (hasIncludes) {
message = nls.localize('noResultsIncludes', "No results found in '{0}' - ", includePatternText);
} else if (hasExcludes) {
message = nls.localize('noResultsExcludes', "No results found excluding '{0}' - ", excludePatternText);
} else {
message = nls.localize('noResultsFound', "No results found. Review your settings for configured exclusions and ignore files - ");
if (completed && completed.limitHit) {
this.searchWidget.searchInput.showMessage({
content: nls.localize('searchMaxResultsWarning', "The result set only contains a subset of all matches. Please be more specific in your search to narrow down the results."),
type: MessageType.WARNING
});
}

// Indicate as status to ARIA
aria.status(message);

this.tree.onHidden();
dom.hide(this.resultsElement);
if (!hasResults) {
let hasExcludes = !!excludePatternText;
let hasIncludes = !!includePatternText;
let message: string;

if (!completed) {
message = nls.localize('searchCanceled', "Search was canceled before any results could be found - ");
} else if (hasIncludes && hasExcludes) {
message = nls.localize('noResultsIncludesExcludes', "No results found in '{0}' excluding '{1}' - ", includePatternText, excludePatternText);
} else if (hasIncludes) {
message = nls.localize('noResultsIncludes', "No results found in '{0}' - ", includePatternText);
} else if (hasExcludes) {
message = nls.localize('noResultsExcludes', "No results found excluding '{0}' - ", excludePatternText);
} else {
message = nls.localize('noResultsFound', "No results found. Review your settings for configured exclusions and ignore files - ");
}

const messageEl = this.clearMessage();
const p = dom.append(messageEl, $('p', undefined, message));
// Indicate as status to ARIA
aria.status(message);

if (!completed) {
const searchAgainLink = dom.append(p, $('a.pointer.prominent', undefined, nls.localize('rerunSearch.message', "Search again")));
this.messageDisposables.push(dom.addDisposableListener(searchAgainLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);
this.onQueryChanged();
}));
} else if (hasIncludes || hasExcludes) {
const searchAgainLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('rerunSearchInAll.message', "Search again in all files")));
this.messageDisposables.push(dom.addDisposableListener(searchAgainLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);
this.tree.onHidden();
dom.hide(this.resultsElement);

this.inputPatternExcludes.setValue('');
this.inputPatternIncludes.setValue('');
const messageEl = this.clearMessage();
const p = dom.append(messageEl, $('p', undefined, message));

if (!completed) {
const searchAgainLink = dom.append(p, $('a.pointer.prominent', undefined, nls.localize('rerunSearch.message', "Search again")));
this.messageDisposables.push(dom.addDisposableListener(searchAgainLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);
this.onQueryChanged();
}));
} else if (hasIncludes || hasExcludes) {
const searchAgainLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('rerunSearchInAll.message', "Search again in all files")));
this.messageDisposables.push(dom.addDisposableListener(searchAgainLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);

this.inputPatternExcludes.setValue('');
this.inputPatternIncludes.setValue('');

this.onQueryChanged();
}));
} else {
const openSettingsLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('openSettings.message', "Open Settings")));
this.addClickEvents(openSettingsLink, this.onOpenSettings);
}

this.onQueryChanged();
}));
} else {
const openSettingsLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('openSettings.message', "Open Settings")));
this.addClickEvents(openSettingsLink, this.onOpenSettings);
}
if (completed) {
dom.append(p, $('span', undefined, ' - '));

if (completed) {
dom.append(p, $('span', undefined, ' - '));
const learnMoreLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('openSettings.learnMore', "Learn More")));
this.addClickEvents(learnMoreLink, this.onLearnMore);
}

const learnMoreLink = dom.append(p, $('a.pointer.prominent', { tabindex: 0 }, nls.localize('openSettings.learnMore', "Learn More")));
this.addClickEvents(learnMoreLink, this.onLearnMore);
}
if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) {
this.showSearchWithoutFolderMessage();
}
} else {
this.viewModel.searchResult.toggleHighlights(this.isVisible()); // show highlights

if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) {
this.showSearchWithoutFolderMessage();
// Indicate final search result count for ARIA
aria.status(nls.localize('ariaSearchResultsStatus', "Search returned {0} results in {1} files", this.viewModel.searchResult.count(), this.viewModel.searchResult.fileCount()));
}
} else {
this.viewModel.searchResult.toggleHighlights(this.isVisible()); // show highlights

// Indicate final search result count for ARIA
aria.status(nls.localize('ariaSearchResultsStatus', "Search returned {0} results in {1} files", this.viewModel.searchResult.count(), this.viewModel.searchResult.fileCount()));
}
});
};

let onError = (e: any) => {
if (errors.isPromiseCanceledError(e)) {
onComplete(null);
return onComplete(null);
} else {
this.searching = false;
this.changeActionAtPosition(0, this.instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL));
Expand All @@ -1269,6 +1277,8 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
} else if (e.code === SearchErrorCode.regexParseError && !this.configurationService.getValue('search.usePCRE2')) {
this.showPcre2Hint();
}

return Promise.resolve();
}
};

Expand Down Expand Up @@ -1331,7 +1341,8 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {

this.searchWidget.setReplaceAllActionState(false);

this.viewModel.search(query, onProgress).then(onComplete, onError);
return this.viewModel.search(query, onProgress)
.then(onComplete, onError);
}

private showPcre2Hint(): void {
Expand Down

0 comments on commit 58177b4

Please sign in to comment.