source: frontend/node_modules/v8-to-istanbul/lib/range.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 963 bytes
Line 
1/**
2 * ...something resembling a binary search, to find the lowest line within the range.
3 * And then you could break as soon as the line is longer than the range...
4 */
5module.exports.sliceRange = (lines, startCol, endCol, inclusive = false) => {
6 let start = 0
7 let end = lines.length - 1
8
9 /**
10 * I consider this a temporary solution until I find an alternaive way to fix the "off by one issue"
11 */
12 const extStartCol = inclusive ? startCol - 1 : startCol
13
14 while (start < end) {
15 const mid = (start + end) >> 1
16 if (lines[mid].startCol <= startCol && lines[mid].endCol > extStartCol) {
17 start = mid
18 end = start
19 } else if (lines[mid].startCol > startCol) {
20 end = mid - 1
21 } else {
22 start = mid + 1
23 }
24 }
25 if (start === end) {
26 while (end < lines.length && extStartCol < lines[end].endCol && endCol >= lines[end].startCol) {
27 ++end
28 }
29 return lines.slice(start, end)
30 } else {
31 return []
32 }
33}
Note: See TracBrowser for help on using the repository browser.