From 64be45bd003ae340f35c85e44d030901f98f2d91 Mon Sep 17 00:00:00 2001 From: Matthieu Baerts Date: Tue, 14 Jul 2026 11:00:16 +0200 Subject: [PATCH] logview: add anchors for each line So we can easily point to a part of it. When the user clicks on the page, the anchor is added in the URL, which can be easily copied. Signed-off-by: Matthieu Baerts --- ui/logview.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ui/logview.html b/ui/logview.html index e5dc7a4..0e35028 100644 --- a/ui/logview.html +++ b/ui/logview.html @@ -158,13 +158,15 @@ const lines = text.split("\n"); let pass = 0, fail = 0, skip = 0; - function renderLine(line) { + function renderLine(line, i) { const cls = classify(line); if (cls === "ln-pass") pass++; else if (cls === "ln-fail") fail++; else if (cls === "ln-skip") skip++; const e = esc(line); - return cls ? `${e}` : e; + const c = cls ? `class=${cls}` : ``; + if (this.add) i += this.add; + return `${e}`; } // Group runs of deeply-nested "# #" diagnostic lines into a foldable @@ -177,13 +179,13 @@ if (foldable(lines[i])) { let j = i; while (j < lines.length && foldable(lines[j])) j++; - const body = lines.slice(i, j).map(renderLine).join("\n"); + const body = lines.slice(i, j).map(renderLine, {add: i}).join("\n"); pieces.push( `${j - i} lines` + `\n${body}`); i = j; } else { - pieces.push(renderLine(lines[i])); + pieces.push(renderLine(lines[i], i, {add: 0})); i++; } } @@ -199,6 +201,11 @@ out.addEventListener("click", e => { const t = e.target.closest(".fold-toggle"); if (t) t.parentElement.classList.toggle("open"); + + // Set #Line in url + var id = e.target.id; + if (id && id.startsWith("L")) + history.pushState(null, null, "#" + id); }); // Fold/unfold all button.