Skip to content

Commit

Permalink
Chore: Apply review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwade committed May 19, 2021
1 parent e0156d0 commit cba69f2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/source-code/source-code.js
Expand Up @@ -530,11 +530,12 @@ class SourceCode extends TokenStore {
}

/*
* To figure out which line rangeIndex is on, determine the last index at which rangeIndex could
* be inserted into lineIndices to keep the list sorted.
* To figure out which line index is on, determine the last place at which index could
* be inserted into lineStartIndices to keep the list sorted.
*/
const rangeIndex = [...this.lineStartIndices].reverse().findIndex(el => index >= el);
const lineNumber = rangeIndex === -1 ? 0 : this.lineStartIndices.length - rangeIndex;
const lineNumber = index >= this.lineStartIndices[this.lineStartIndices.length - 1]
? this.lineStartIndices.length
: this.lineStartIndices.findIndex(el => index < el);

return { line: lineNumber, column: index - this.lineStartIndices[lineNumber - 1] };
}
Expand Down

0 comments on commit cba69f2

Please sign in to comment.