diff options
Diffstat (limited to 'coverage/htmlfiles')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 30 | ||||
-rw-r--r-- | coverage/htmlfiles/pyfile.html | 4 | ||||
-rw-r--r-- | coverage/htmlfiles/style.css | 8 | ||||
-rw-r--r-- | coverage/htmlfiles/style.scss | 18 |
4 files changed, 32 insertions, 28 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index edd0782e..d031e595 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -19,9 +19,10 @@ function debounce(callback, wait) { }; function checkVisible(element) { - var rect = element.getBoundingClientRect(); - var viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight); - return !(rect.bottom < 0 || rect.top - viewHeight >= 0); + const rect = element.getBoundingClientRect(); + const viewBottom = Math.max(document.documentElement.clientHeight, window.innerHeight); + const viewTop = 30; + return !(rect.bottom < viewTop || rect.top >= viewBottom); } // Helpers for table sorting @@ -204,7 +205,7 @@ coverage.pyfile_ready = function () { // If we're directed to a particular line number, highlight the line. var frag = location.hash; if (frag.length > 2 && frag[1] === 't') { - document.getElementById(frag.substring(1)).classList.add("highlight"); + document.querySelector(frag).closest(".n").classList.add("highlight"); coverage.set_sel(parseInt(frag.substr(2), 10)); } else { coverage.set_sel(0); @@ -245,7 +246,7 @@ coverage.pyfile_ready = function () { }; coverage.toggle_lines = function (event) { - const btn = event.target; + const btn = event.target.closest("button"); const category = btn.value const show = !btn.classList.contains("show_" + category); coverage.set_line_visibilty(category, show); @@ -271,7 +272,7 @@ coverage.set_line_visibilty = function (category, should_show) { // Return the nth line div. coverage.line_elt = function (n) { - return document.getElementById("t" + n); + return document.getElementById("t" + n)?.closest("p"); }; // Set the selection. b and e are line numbers. @@ -295,7 +296,7 @@ coverage.to_first_chunk = function () { // Return a string indicating what kind of chunk this line belongs to, // or null if not a chunk. coverage.chunk_indicator = function (line_elt) { - const classes = line_elt.className; + const classes = line_elt?.className; if (!classes) { return null; } @@ -344,11 +345,11 @@ coverage.to_prev_chunk = function () { // Find the end of the prev colored chunk. var probe = c.sel_begin-1; var probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { return; } var chunk_indicator = c.chunk_indicator(probe_line); - while (probe > 0 && !chunk_indicator) { + while (probe > 1 && !chunk_indicator) { probe--; probe_line = c.line_elt(probe); if (!probe_line) { @@ -364,6 +365,9 @@ coverage.to_prev_chunk = function () { var prev_indicator = chunk_indicator; while (prev_indicator === chunk_indicator) { probe--; + if (probe <= 0) { + return; + } probe_line = c.line_elt(probe); prev_indicator = c.chunk_indicator(probe_line); } @@ -430,7 +434,7 @@ coverage.to_prev_chunk_nicely = function () { coverage.select_line_or_chunk = function (lineno) { var c = coverage; var probe_line = c.line_elt(lineno); - if (probe_line.length === 0) { + if (!probe_line) { return; } var the_indicator = c.chunk_indicator(probe_line); @@ -442,7 +446,7 @@ coverage.select_line_or_chunk = function (lineno) { while (probe > 0 && indicator === the_indicator) { probe--; probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { break; } indicator = c.chunk_indicator(probe_line); @@ -469,7 +473,7 @@ coverage.show_selection = function () { // Highlight the lines in the chunk document.querySelectorAll("#source .highlight").forEach(e => e.classList.remove("highlight")); for (let probe = coverage.sel_begin; probe < coverage.sel_end; probe++) { - coverage.line_elt(probe).classList.add("highlight"); + coverage.line_elt(probe).querySelector(".n").classList.add("highlight"); } coverage.scroll_to_selection(); @@ -479,7 +483,7 @@ coverage.scroll_to_selection = function () { // Scroll the page if the chunk isn't fully visible. if (coverage.selection_ends_on_screen() < 2) { const element = coverage.line_elt(coverage.sel_begin); - coverage.scroll_window(element.offsetTop - 30); + coverage.scroll_window(element.offsetTop - 60); } }; diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html index 523f8483..1f7b6bd2 100644 --- a/coverage/htmlfiles/pyfile.html +++ b/coverage/htmlfiles/pyfile.html @@ -75,8 +75,8 @@ <main id="source"> {% for line in lines -%} {% joined %} - <p id="t{{line.number}}" class="{{line.css_class}}"> - <span class="n"><a href="#t{{line.number}}">{{line.number}}</a></span> + <p class="{{line.css_class}}"> + <span class="n"><a id="t{{line.number}}" href="#t{{line.number}}">{{line.number}}</a></span> <span class="t">{{line.html}} </span> {% if line.context_list %} <input type="checkbox" id="ctxs{{line.number}}" /> diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css index 2cabc74c..3b4643a1 100644 --- a/coverage/htmlfiles/style.css +++ b/coverage/htmlfiles/style.css @@ -140,7 +140,7 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em #source { padding: 1em 0 1em 3.5rem; font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; } -#source p { margin-top: -4em; padding-top: 4em; position: relative; white-space: pre; } +#source p { position: relative; white-space: pre; } #source p * { box-sizing: border-box; } @@ -148,7 +148,9 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em @media (prefers-color-scheme: dark) { #source p .n { color: #777; } } -#source p .n a { text-decoration: none; color: #999; } +#source p .n.highlight { background: #ffdd00; } + +#source p .n a { margin-top: -4em; padding-top: 4em; text-decoration: none; color: #999; } @media (prefers-color-scheme: dark) { #source p .n a { color: #777; } } @@ -156,8 +158,6 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em @media (prefers-color-scheme: dark) { #source p .n a:hover { color: #777; } } -#source p.highlight .n { background: #ffdd00; } - #source p .t { display: inline-block; width: 100%; box-sizing: border-box; margin-left: -.5em; padding-left: 0.3em; border-left: 0.2em solid #fff; } @media (prefers-color-scheme: dark) { #source p .t { border-color: #1e1e1e; } } diff --git a/coverage/htmlfiles/style.scss b/coverage/htmlfiles/style.scss index 775cdcb6..e4826f31 100644 --- a/coverage/htmlfiles/style.scss +++ b/coverage/htmlfiles/style.scss @@ -395,11 +395,6 @@ $border-indicator-width: .2em; font-family: $font-code; p { - // These two lines make anchors to the line scroll the line to be - // visible beneath the fixed-position header. - margin-top: -4em; - padding-top: 4em; - // position relative makes position:absolute pop-ups appear in the right place. position: relative; white-space: pre; @@ -418,7 +413,16 @@ $border-indicator-width: .2em; color: $light-gray4; @include color-dark($dark-gray4); + &.highlight { + background: #ffdd00; + } + a { + // These two lines make anchors to the line scroll the line to be + // visible beneath the fixed-position header. + margin-top: -4em; + padding-top: 4em; + text-decoration: none; color: $light-gray4; @include color-dark($dark-gray4); @@ -430,10 +434,6 @@ $border-indicator-width: .2em; } } - &.highlight .n { - background: #ffdd00; - } - .t { display: inline-block; width: 100%; |