summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-02-27 15:44:20 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-02-27 15:44:20 -0500
commit8750045b3dd2cd7530bb2795f2d7a36f89353225 (patch)
tree8bfc95b81e0a43a5a83957ca00f7a42202c62a22
parentc7052bb24da03b5112c6d7fd1386936e211223f0 (diff)
downloadpython-coveragepy-git-8750045b3dd2cd7530bb2795f2d7a36f89353225.tar.gz
fix: HTML line visibility is saved in local storage #1123
Seems like we could unify the two different uses of localStorage, but that's for another time. Fixes: #1123
-rw-r--r--CHANGES.rst11
-rw-r--r--coverage/htmlfiles/coverage_html.js43
2 files changed, 44 insertions, 10 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 7eaf22a2..201f1d06 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -29,13 +29,20 @@ Unreleased
they have been combined. This was requested in `issue 1108`_ and implemented
in `pull request 1110`_. Thanks, Éric Larivière.
-- The HTML report has a little more room for line numbers so that 4-digit
- numbers work well, fixing `issue 1124`_.
+- Minor improvements to the HTML report:
+
+ - The state of the line visibility selector buttons is saved in local storage
+ so you don't have to fiddle with them so often, fixing `issue 1123`_.
+
+ - It has a little more room for line numbers so that 4-digit numbers work
+ well, fixing `issue 1124`_.
.. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108
.. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110
+.. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123
.. _issue 1124: https://github.com/nedbat/coveragepy/issues/1124
+
.. _changes_54:
Version 5.4 --- 2021-01-24
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 6bc9fdf5..27b49b36 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -233,6 +233,8 @@ coverage.index_ready = function ($) {
// -- pyfile stuff --
+coverage.LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS";
+
coverage.pyfile_ready = function ($) {
// If we're directed to a particular line number, highlight the line.
var frag = location.hash;
@@ -256,6 +258,22 @@ coverage.pyfile_ready = function ($) {
$(".button_toggle_mis").click(function (evt) {coverage.toggle_lines(evt.target, "mis");});
$(".button_toggle_par").click(function (evt) {coverage.toggle_lines(evt.target, "par");});
+ coverage.filters = undefined;
+ try {
+ coverage.filters = localStorage.getItem(coverage.LINE_FILTERS_STORAGE);
+ } catch(err) {}
+
+ if (coverage.filters) {
+ coverage.filters = JSON.parse(coverage.filters);
+ }
+ else {
+ coverage.filters = {run: false, exc: true, mis: true, par: true};
+ }
+
+ for (cls in coverage.filters) {
+ coverage.set_line_visibilty(cls, coverage.filters[cls]);
+ }
+
coverage.assign_shortkeys();
coverage.wire_up_help_panel();
@@ -266,17 +284,26 @@ coverage.pyfile_ready = function ($) {
};
coverage.toggle_lines = function (btn, cls) {
- btn = $(btn);
- var show = "show_"+cls;
- if (btn.hasClass(show)) {
- $("#source ." + cls).removeClass(show);
- btn.removeClass(show);
- }
- else {
+ var onoff = !$(btn).hasClass("show_" + cls);
+ coverage.set_line_visibilty(cls, onoff);
+ coverage.build_scroll_markers();
+ coverage.filters[cls] = onoff;
+ try {
+ localStorage.setItem(coverage.LINE_FILTERS_STORAGE, JSON.stringify(coverage.filters));
+ } catch(err) {}
+};
+
+coverage.set_line_visibilty = function (cls, onoff) {
+ var show = "show_" + cls;
+ var btn = $(".button_toggle_" + cls);
+ if (onoff) {
$("#source ." + cls).addClass(show);
btn.addClass(show);
}
- coverage.build_scroll_markers();
+ else {
+ $("#source ." + cls).removeClass(show);
+ btn.removeClass(show);
+ }
};
// Return the nth line div.