Skip to content

Commit 64be45b

Browse files
committed
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 <matttbe@kernel.org>
1 parent a726610 commit 64be45b

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

ui/logview.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@
158158
const lines = text.split("\n");
159159
let pass = 0, fail = 0, skip = 0;
160160

161-
function renderLine(line) {
161+
function renderLine(line, i) {
162162
const cls = classify(line);
163163
if (cls === "ln-pass") pass++;
164164
else if (cls === "ln-fail") fail++;
165165
else if (cls === "ln-skip") skip++;
166166
const e = esc(line);
167-
return cls ? `<span class="${cls}">${e}</span>` : e;
167+
const c = cls ? `class=${cls}` : ``;
168+
if (this.add) i += this.add;
169+
return `<span id="L${i}" ${c}>${e}</span>`;
168170
}
169171

170172
// Group runs of deeply-nested "# #" diagnostic lines into a foldable
@@ -177,13 +179,13 @@
177179
if (foldable(lines[i])) {
178180
let j = i;
179181
while (j < lines.length && foldable(lines[j])) j++;
180-
const body = lines.slice(i, j).map(renderLine).join("\n");
182+
const body = lines.slice(i, j).map(renderLine, {add: i}).join("\n");
181183
pieces.push(
182184
`<span class="fold open"><span class="fold-toggle">${j - i} lines` +
183185
`</span><span class="fold-body">\n${body}</span></span>`);
184186
i = j;
185187
} else {
186-
pieces.push(renderLine(lines[i]));
188+
pieces.push(renderLine(lines[i], i, {add: 0}));
187189
i++;
188190
}
189191
}
@@ -199,6 +201,11 @@
199201
out.addEventListener("click", e => {
200202
const t = e.target.closest(".fold-toggle");
201203
if (t) t.parentElement.classList.toggle("open");
204+
205+
// Set #Line in url
206+
var id = e.target.id;
207+
if (id && id.startsWith("L"))
208+
history.pushState(null, null, "#" + id);
202209
});
203210

204211
// Fold/unfold all button.

0 commit comments

Comments
 (0)