-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderFixInBrowser.js
33 lines (30 loc) · 999 Bytes
/
renderFixInBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {htmlRenderFunc} from './renderInBrowser.js';
export async function renderFix(fix) {
// Clear the test results from the dom first.
document.body.innerHTML = '';
const fixClassName = 'fix-line';
const tcStartClassName = 'fix-tc-start';
fix.lines.forEach((line, idx) => {
if (fix.tcBlocks.length > 0 && idx == fix.tcBlocks[0].startIdx - 1) {
htmlRenderFunc(`<span class='${tcStartClassName}'>${line}</span>`);
return;
}
if (isWithinIntervals(idx, fix.changeIntervals)) {
htmlRenderFunc(`<span class='${fixClassName}' style='background-color:#C4FFC1'>${line}</span>`);
return;
}
htmlRenderFunc(line);
});
const tcStarts = document.getElementsByClassName(tcStartClassName);
if (tcStarts.length > 0) {
tcStarts[0].scrollIntoView();
}
}
function isWithinIntervals(idx, intervals) {
for (const interval of intervals) {
if (interval.startIdx <= idx && idx < interval.endIdx) {
return true;
}
}
return false;
}