keep search more stable while results are coming in
- you can collapse/expand results and this is preserved - the "collapse all" action enables once results arrive - you can remove results and they dont come back at the end of the search - we do not add the same matches over and over again to the tree, but only once per result
This commit is contained in:
parent
0f09edce01
commit
96d34d983d
|
@ -73,7 +73,6 @@ export interface ISearchComplete {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---- very simple implementation of the search model --------------------
|
// ---- very simple implementation of the search model --------------------
|
||||||
|
|
||||||
export class FileMatch implements IFileMatch {
|
export class FileMatch implements IFileMatch {
|
||||||
|
|
|
@ -1148,6 +1148,7 @@ export class SearchViewlet extends Viewlet {
|
||||||
this.disposeModel();
|
this.disposeModel();
|
||||||
this.showEmptyStage();
|
this.showEmptyStage();
|
||||||
|
|
||||||
|
let handledMatches: {[id: string]: boolean} = Object.create(null);
|
||||||
let autoExpand = (alwaysExpandIfOneResult: boolean) => {
|
let autoExpand = (alwaysExpandIfOneResult: boolean) => {
|
||||||
// Auto-expand / collapse based on number of matches:
|
// Auto-expand / collapse based on number of matches:
|
||||||
// - alwaysExpandIfOneResult: expand file results if we have just one file result and less than 50 matches on a file
|
// - alwaysExpandIfOneResult: expand file results if we have just one file result and less than 50 matches on a file
|
||||||
|
@ -1155,6 +1156,12 @@ export class SearchViewlet extends Viewlet {
|
||||||
if (this.viewModel) {
|
if (this.viewModel) {
|
||||||
let matches = this.viewModel.matches();
|
let matches = this.viewModel.matches();
|
||||||
matches.forEach((match) => {
|
matches.forEach((match) => {
|
||||||
|
if (handledMatches[match.id()]) {
|
||||||
|
return; // if we once handled a result, do not do it again to keep results stable (the user might have expanded/collapsed meanwhile)
|
||||||
|
}
|
||||||
|
|
||||||
|
handledMatches[match.id()] = true;
|
||||||
|
|
||||||
let length = match.matches().length;
|
let length = match.matches().length;
|
||||||
if (length < 10 || (alwaysExpandIfOneResult && matches.length === 1 && length < 50)) {
|
if (length < 10 || (alwaysExpandIfOneResult && matches.length === 1 && length < 50)) {
|
||||||
this.tree.expand(match).done(null, errors.onUnexpectedError);
|
this.tree.expand(match).done(null, errors.onUnexpectedError);
|
||||||
|
@ -1180,9 +1187,12 @@ export class SearchViewlet extends Viewlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the final results
|
// Show the final results
|
||||||
this.viewModel = this.viewModel || this.instantiationService.createInstance(SearchResult, query.contentPattern);
|
if (!this.viewModel) {
|
||||||
if (completed) {
|
this.viewModel = this.instantiationService.createInstance(SearchResult, query.contentPattern);
|
||||||
this.viewModel.append(completed.results);
|
|
||||||
|
if (completed) {
|
||||||
|
this.viewModel.append(completed.results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tree.refresh().then(() => {
|
this.tree.refresh().then(() => {
|
||||||
|
@ -1308,7 +1318,7 @@ export class SearchViewlet extends Viewlet {
|
||||||
}).done(null, errors.onUnexpectedError);
|
}).done(null, errors.onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.viewModel.append(matches);
|
this.viewModel.append([p]);
|
||||||
progressTimer.stop();
|
progressTimer.stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1344,6 +1354,11 @@ export class SearchViewlet extends Viewlet {
|
||||||
this.tree.refresh().then(() => {
|
this.tree.refresh().then(() => {
|
||||||
autoExpand(false);
|
autoExpand(false);
|
||||||
}).done(null, errors.onUnexpectedError);
|
}).done(null, errors.onUnexpectedError);
|
||||||
|
|
||||||
|
// since we have results now, enable some actions
|
||||||
|
if (!this.actionRegistry['collapseAll'].enabled) {
|
||||||
|
this.actionRegistry['collapseAll'].enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue