Live logs (run log, job tails, runner log) keep the reader's lines in place when scrolled away from the end
Browse files at this commit7aca449414b1903381696744a8b9bc4f3efe29eaParent: 08e885bChecks pending
Show checks
ci/buildQueuedDetails
- fix
- live logs (run log, job tails, runner log) keep the reader's lines in place when scrolled away from the end
- at the end they keep following
1 changed file +37 -16
- crates/forge-web/assets/nav.js +37 -16
crates/forge-web/assets/nav.jsmodified+37 -16
| @@ -175,7 +175,7 @@ | ||
| 175 | 175 | if (pending === 0 && !waiting) { dropExtras(); } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - function adopt(doc, keepFields, dd, jobs) { | |
| 178 | + function adopt(doc, keepFields, dd, jobs, logs) { | |
| 179 | 179 | document.title = doc.title; |
| 180 | 180 | ['lang', 'data-theme', 'data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark', 'data-sidebar', 'data-ui', 'data-rel-words', 'data-rel-now'].forEach(function (name) { |
| 181 | 181 | if (doc.documentElement.hasAttribute(name)) { root.setAttribute(name, doc.documentElement.getAttribute(name)); } |
| @@ -208,6 +208,7 @@ | ||
| 208 | 208 | syncLog(); |
| 209 | 209 | followTail(); |
| 210 | 210 | restoreJobs(jobs); |
| 211 | + restoreLogs(logs); | |
| 211 | 212 | syncLive(); |
| 212 | 213 | syncPush(); |
| 213 | 214 | syncTick(); |
| @@ -271,26 +272,51 @@ | ||
| 271 | 272 | var open = li.getAttribute('data-open') === 'true'; |
| 272 | 273 | out[li.getAttribute('data-job-row')] = { |
| 273 | 274 | touched: li.hasAttribute('data-touched'), |
| 274 | - open: open, | |
| 275 | - top: pre && open ? pre.scrollTop : 0, | |
| 276 | - end: pre && open ? pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 24 : true | |
| 275 | + open: open | |
| 277 | 276 | }; |
| 278 | 277 | }); |
| 279 | 278 | return out; |
| 280 | 279 | } |
| 281 | 280 | |
| 282 | - // Every open tail starts at its end; a captured one goes back to where the reader had it. | |
| 283 | 281 | function restoreJobs(kept) { |
| 284 | 282 | jobTails().forEach(function (li) { |
| 285 | 283 | var c = kept ? kept[li.getAttribute('data-job-row')] : null; |
| 286 | 284 | if (c && c.touched) { setJobRow(li, c.open, true); } |
| 287 | - var pre = li.querySelector('[data-job-tail] pre'); | |
| 288 | - if (!pre || li.getAttribute('data-open') !== 'true') { return; } | |
| 289 | - pre.scrollTop = c && !c.end ? c.top : pre.scrollHeight; | |
| 290 | 285 | }); |
| 291 | 286 | syncJobAll(); |
| 292 | 287 | } |
| 293 | 288 | |
| 289 | + // Live logs: the run's log, the job row tails, the runner log. A live swap brings the server's last | |
| 290 | + // window of the log, which slides as lines come. A log at its end stays at its end. A log the reader | |
| 291 | + // scrolled away from keeps its own element, so the lines under their eyes do not move. | |
| 292 | + function liveLogs() { return document.querySelectorAll('pre[data-live-log], [data-job-tail] pre, pre#runner-log'); } | |
| 293 | + | |
| 294 | + function logKey(pre) { | |
| 295 | + var row = pre.closest('[data-job-row]'); | |
| 296 | + return row ? 'job:' + row.getAttribute('data-job-row') : (pre.id || 'live'); | |
| 297 | + } | |
| 298 | + | |
| 299 | + function captureLogs() { | |
| 300 | + var out = {}; | |
| 301 | + Array.prototype.forEach.call(liveLogs(), function (pre) { | |
| 302 | + if (!pre.clientHeight) { return; } | |
| 303 | + var end = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 24; | |
| 304 | + out[logKey(pre)] = { pre: pre, top: pre.scrollTop, follow: end && !pre.hasAttribute('data-log-start') }; | |
| 305 | + }); | |
| 306 | + return out; | |
| 307 | + } | |
| 308 | + | |
| 309 | + function restoreLogs(kept) { | |
| 310 | + if (!kept) { return; } | |
| 311 | + Array.prototype.forEach.call(liveLogs(), function (pre) { | |
| 312 | + var c = kept[logKey(pre)]; | |
| 313 | + if (!c) { return; } | |
| 314 | + if (c.follow) { pre.scrollTop = pre.scrollHeight; return; } | |
| 315 | + pre.replaceWith(c.pre); | |
| 316 | + c.pre.scrollTop = c.top; | |
| 317 | + }); | |
| 318 | + } | |
| 319 | + | |
| 294 | 320 | // A job's steps dropdown (details[data-steps-job]) the reader opened or shut is marked data-touched; |
| 295 | 321 | // a live swap or a soft navigation keeps that state for the same job. Untouched ones take the server's |
| 296 | 322 | // default: open for the selected job. |
| @@ -357,9 +383,7 @@ | ||
| 357 | 383 | if (!doc.body) { location.assign(dest.href); return; } |
| 358 | 384 | var x = window.scrollX, y = window.scrollY; |
| 359 | 385 | var saved = history.state; |
| 360 | - // A live swap keeps the log tail where the reader had it: at the end it stays at the end. | |
| 361 | - var tail = how === 'live' ? document.querySelector('[data-live-log]') : null; | |
| 362 | - var tailAt = tail ? { top: tail.scrollTop, end: tail.scrollTop + tail.clientHeight >= tail.scrollHeight - 24, start: tail.hasAttribute('data-log-start') } : null; | |
| 386 | + var logs = how === 'live' ? captureLogs() : null; | |
| 363 | 387 | // A live change must not shut a menu the reader has open (a run's branch picker, say). |
| 364 | 388 | var dd = how === 'live' ? captureDropdowns() : null; |
| 365 | 389 | var at = how === 'live' ? captureAnchor() : null; |
| @@ -373,15 +397,12 @@ | ||
| 373 | 397 | var jumped = jump ? jump.value : ''; |
| 374 | 398 | liveJump = null; |
| 375 | 399 | var steps = captureSteps(); |
| 376 | - adopt(doc, keepFields, dd, how === 'live' ? captureJobs() : null); | |
| 400 | + adopt(doc, keepFields, dd, how === 'live' ? captureJobs() : null, logs); | |
| 377 | 401 | restoreSteps(steps); |
| 378 | 402 | placeRun(listTop); |
| 379 | 403 | if (bars) { growBars(bars); } |
| 380 | 404 | if (paneTops) { setPaneScrolls(paneTops); } |
| 381 | - if (tailAt) { | |
| 382 | - var nextTail = document.querySelector('[data-live-log]'); | |
| 383 | - if (nextTail) { nextTail.scrollTop = tailAt.end && !tailAt.start ? nextTail.scrollHeight : tailAt.top; } | |
| 384 | - } | |
| 405 | + if (logs) { restoreLogs(logs); } | |
| 385 | 406 | if (how === 'nav') { history.pushState(null, '', dest.href); } |
| 386 | 407 | else if (how === 'post' || how === 'query') { history.replaceState(null, '', dest.href); } |
| 387 | 408 | shown = dest.pathname + dest.search; |