Skip to content

Commit

Permalink
Change to take an options object,
Browse files Browse the repository at this point in the history
and move MAX_SEARCH_RANGES check (PR feedback)
  • Loading branch information
roblourens committed Jul 26, 2016
1 parent 47367f1 commit e4de85e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ export class SearchState {
public set searchString(search: string){
if (this._searchString !== search) {
this._searchString = search;
this._recalculateSearchRanges(/*forceRecalc=*/true);
this._recalculateSearchRanges({ forceRecalc: true });
}
}

private _recalculateSearchRanges(forceRecalc?: boolean): void {
private _recalculateSearchRanges({ forceRecalc }: { forceRecalc?: boolean } = {}): void {
const search = this.searchString;

if (search === "") { return; }
Expand All @@ -174,12 +174,17 @@ export class SearchState {
this._matchesDocVersion = TextEditor.getDocumentVersion();
this._matchRanges = [];

for (let lineIdx = 0; lineIdx < TextEditor.getLineCount() && this._matchRanges.length < SearchState.MAX_SEARCH_RANGES; lineIdx++) {
outer:
for (let lineIdx = 0; lineIdx < TextEditor.getLineCount(); lineIdx++) {
const line = TextEditor.getLineAt(new Position(lineIdx, 0)).text;

let i = line.indexOf(search);

for (; i !== -1 && this._matchRanges.length < SearchState.MAX_SEARCH_RANGES; i = line.indexOf(search, i + search.length)) {
for (; i !== -1; i = line.indexOf(search, i + search.length)) {
if (this._matchRanges.length >= SearchState.MAX_SEARCH_RANGES) {
break outer;
}

this._matchRanges.push(new vscode.Range(
new Position(lineIdx, i),
new Position(lineIdx, i + search.length)
Expand Down

0 comments on commit e4de85e

Please sign in to comment.