1 | var jumpToCode = (function init () {
|
2 |
|
3 | var missingCoverageClasses = [ '.cbranch-no', '.cstat-no', '.fstat-no' ];
|
4 |
|
5 |
|
6 | var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > ';
|
7 |
|
8 |
|
9 | var selector = notSelector + missingCoverageClasses.join(', ' + notSelector);
|
10 |
|
11 |
|
12 | var missingCoverageElements = document.querySelectorAll(selector);
|
13 |
|
14 | var currentIndex;
|
15 |
|
16 | function toggleClass(index) {
|
17 | missingCoverageElements.item(currentIndex).classList.remove('highlighted');
|
18 | missingCoverageElements.item(index).classList.add('highlighted');
|
19 | }
|
20 |
|
21 | function makeCurrent(index) {
|
22 | toggleClass(index);
|
23 | currentIndex = index;
|
24 | missingCoverageElements.item(index)
|
25 | .scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
|
26 | }
|
27 |
|
28 | function goToPrevious() {
|
29 | var nextIndex = 0;
|
30 | if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
31 | nextIndex = missingCoverageElements.length - 1;
|
32 | } else if (missingCoverageElements.length > 1) {
|
33 | nextIndex = currentIndex - 1;
|
34 | }
|
35 |
|
36 | makeCurrent(nextIndex);
|
37 | }
|
38 |
|
39 | function goToNext() {
|
40 | var nextIndex = 0;
|
41 |
|
42 | if (typeof currentIndex === 'number' && currentIndex < (missingCoverageElements.length - 1)) {
|
43 | nextIndex = currentIndex + 1;
|
44 | }
|
45 |
|
46 | makeCurrent(nextIndex);
|
47 | }
|
48 |
|
49 | return function jump(event) {
|
50 | switch (event.which) {
|
51 | case 78:
|
52 | case 74:
|
53 | goToNext();
|
54 | break;
|
55 | case 66:
|
56 | case 75:
|
57 | case 80:
|
58 | goToPrevious();
|
59 | break;
|
60 | }
|
61 | };
|
62 | }());
|
63 | window.addEventListener('keydown', jumpToCode);
|