Skip to content

Commit 94e3388

Browse files
authored
feat: remember the values for 'filter' and 'hide 100% covered' in HTML report. (#1776)
1 parent 695b8bc commit 94e3388

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

coverage/htmlfiles/coverage_html.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ coverage.assign_shortkeys = function () {
125125

126126
// Create the events for the filter box.
127127
coverage.wire_up_filter = function () {
128+
// Populate the filter and hide inputs if there are saved values for them
129+
const saved_filter_value = localStorage.getItem(coverage.FILTER_STORAGE);
130+
if (saved_filter_value) {
131+
document.getElementById("filter").value = saved_filter_value;
132+
}
133+
const saved_hide100_value = localStorage.getItem(coverage.HIDE_STORAGE);
134+
if (saved_hide100_value) {
135+
document.getElementById("hide100").checked = JSON.parse(saved_hide100_value);
136+
}
137+
128138
// Cache elements.
129139
const table = document.querySelector("table.index");
130140
const table_body_rows = table.querySelectorAll("tbody tr");
@@ -138,8 +148,12 @@ coverage.wire_up_filter = function () {
138148
totals[totals.length - 1] = { "numer": 0, "denom": 0 }; // nosemgrep: eslint.detect-object-injection
139149

140150
var text = document.getElementById("filter").value;
151+
// Store filter value
152+
localStorage.setItem(coverage.FILTER_STORAGE, text);
141153
const casefold = (text === text.toLowerCase());
142154
const hide100 = document.getElementById("hide100").checked;
155+
// Store hide value
156+
localStorage.setItem(coverage.HIDE_STORAGE, JSON.stringify(hide100));
143157

144158
// Hide / show elements.
145159
table_body_rows.forEach(row => {
@@ -240,6 +254,8 @@ coverage.wire_up_filter = function () {
240254
document.getElementById("filter").dispatchEvent(new Event("input"));
241255
document.getElementById("hide100").dispatchEvent(new Event("input"));
242256
};
257+
coverage.FILTER_STORAGE = "COVERAGE_FILTER_VALUE";
258+
coverage.HIDE_STORAGE = "COVERAGE_HIDE_VALUE";
243259

244260
// Set up the click-to-sort columns.
245261
coverage.wire_up_sorting = function () {

0 commit comments

Comments
 (0)