Skip to content

Commit

Permalink
Break infinite loop in "focus previous result". Don't run focus next/…
Browse files Browse the repository at this point in the history
…previous at all when not valid
  • Loading branch information
roblourens committed May 31, 2020
1 parent 0201686 commit 79a1f5a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ export class SearchView extends ViewPane {
}

selectNextMatch(): void {
if (!this.hasSearchResults()) {
return;
}

const [selected] = this.tree.getSelection();

// Expand the initial selected node, if needed
Expand Down Expand Up @@ -824,14 +828,24 @@ export class SearchView extends ViewPane {
}

selectPreviousMatch(): void {
if (!this.hasSearchResults()) {
return;
}

const [selected] = this.tree.getSelection();
let navigator = this.tree.navigate(selected);

let prev = navigator.previous();

// Select previous until find a Match or a collapsed item
while (!prev || (!(prev instanceof Match) && !this.tree.isCollapsed(prev))) {
prev = prev ? navigator.previous() : navigator.last();
const nextPrev = prev ? navigator.previous() : navigator.last();

if (!prev && !nextPrev) {
return;
}

prev = nextPrev;
}

// Expand until last child is a Match
Expand Down

0 comments on commit 79a1f5a

Please sign in to comment.