Fix uncaught exception when arrowing through empty search result list
MODIFY
lib/project/results-view.js
lib/project/results-view.js
@@ -201,7 +201,8 @@ class ResultsView {
if (this.collapsedResultIndices[this.selectedResultIndex]) {
this.selectedMatchIndex = -1;
} else {
- this.selectedMatchIndex = this.model.getResultAt(this.selectedResultIndex).matches.length - 1;
+ const selectedResult = this.model.getResultAt(this.selectedResultIndex)
+ if (selectedResult) this.selectedMatchIndex = selectedResult.matches.length - 1;
}
this.scrollToSelectedMatch();
@@ -251,7 +252,7 @@ class ResultsView {
}
selectResultAtPosition(position, pathDetailsHeight, matchHeight) {
- if (this.refs.listView) {
+ if (this.refs.listView && this.model.getPathCount() > 0) {
const {clientHeight} = this.refs.listView.element;
this.selectedResultIndex = this.model.getPathCount() - 1;
this.selectedMatchIndex = this.collapsedResultIndices[this.selectedResultIndex] ?
@@ -305,6 +306,8 @@ class ResultsView {
}
const selectedResult = this.model.getResultAt(this.selectedResultIndex);
+ if (!selectedResult) return;
+
if (this.selectedMatchIndex < selectedResult.matches.length - 1 &&
!this.collapsedResultIndices[this.selectedResultIndex]) {
this.selectedMatchIndex++;

MODIFY
spec/results-view-spec.js
spec/results-view-spec.js
@@ -537,12 +537,18 @@ describe('ResultsView', () => {
});
describe("when the results view is empty", () => {
- it("ignores core:confirm events", async () => {
+ it("ignores core:confirm and other commands for selecting results", async () => {
projectFindView.findEditor.setText('thiswillnotmatchanythingintheproject');
atom.commands.dispatch(projectFindView.element, 'core:confirm');
await searchPromise;
resultsView = getResultsView();
atom.commands.dispatch(resultsView.element, 'core:confirm');
+ atom.commands.dispatch(resultsView.element, 'core:move-down');
+ atom.commands.dispatch(resultsView.element, 'core:move-up');
+ atom.commands.dispatch(resultsView.element, 'core:move-to-top');
+ atom.commands.dispatch(resultsView.element, 'core:move-to-bottom');
+ atom.commands.dispatch(resultsView.element, 'core:page-down');
+ atom.commands.dispatch(resultsView.element, 'core:page-up');
});
it("won't show the preview-controls", async () => {

Fix uncaught exception when arrowing through empty search result list