()
| 262 | toolbar.append(before, after, diff, expand); |
| 263 | host.append(toolbar, body, caption); |
| 264 | function update() { |
| 265 | before.setAttribute('aria-pressed', String(side === 'before')); |
| 266 | after.setAttribute('aria-pressed', String(side === 'after')); |
| 267 | diff.setAttribute('aria-pressed', String(side === 'diff')); |
| 268 | body.replaceChildren(); |
| 269 | expand.hidden = side === 'diff'; |
| 270 | if (side === 'diff') { |
| 271 | const change = changes.get(region.change); |
| 272 | body.append(el('pre', 'source-code', change?.diff ? change.diff.replace(/\x1b\[[0-9;]*m/g, '') : 'Recorded diff unavailable: ' + (change?.diff_status || 'not supplied'))); |
| 273 | caption.textContent = 'Entire selected change diff, not limited to this region. Unchanged caller context may have no hunk.'; |
| 274 | return; |
| 275 | } |
| 276 | const snapshot = snapshots.get(region.change + '\0' + region.path); |
| 277 | const source = snapshot?.[side]; |
| 278 | if (!source || source.status !== 'present') { |
| 279 | body.append(el('p', 'empty', source?.status === 'absent' ? 'This file is absent in this recorded revision.' : source?.reason || 'Recorded source was not exported. No working-copy bytes are substituted.')); |
| 280 | expand.hidden = true; |
| 281 | caption.textContent = viewComparison ? `${side==='before'?'Before':'After'} view ${(side==='before'?comparisonBefore:comparisonAfter).view}` : viewSnapshot ? `Recorded view ${viewSnapshot.view} @ ${viewSnapshot.state}` : `${side} snapshot · change ${region.change}`; |
| 282 | return; |
| 283 | } |
| 284 | const range = counterpart(region, side); |
| 285 | const lines = source.text.split('\n'); |
| 286 | const start = full || !range.start ? 1 : Math.max(1, range.start - 6); |
| 287 | const end = full ? lines.length : Math.min(lines.length, Math.max(start + 30, Math.min((range.end || start) + 6, start + 399))); |
| 288 | const code = el('div', 'source-code'); |
| 289 | code.setAttribute('aria-label', `${side} recorded source, lines ${start} through ${end}`); |
| 290 | for (let i = start; i <= end; i++) { |
| 291 | const line = el('div', 'source-line' + (range.start && i >= range.start && i <= range.end ? ' highlight' : '')); |
| 292 | const number = el('span', 'line-number', i); number.setAttribute('aria-hidden', 'true'); |
| 293 | line.append(number, el('span', 'line-text', lines[i - 1] || ' ')); code.append(line); |
| 294 | } |
| 295 | body.append(code); |
| 296 | expand.textContent = full ? 'Show region context' : 'Show full file'; |
| 297 | const compared=comparedFiles.get(region.change), pin=side==='before'?comparisonBefore:comparisonAfter; |
| 298 | caption.textContent = viewComparison ? `${side==='before'?'Before':'After'} ${pin.view}: ${compared?.[side+'_path'] || region.path}, lines ${start}–${end} of ${lines.length}. State ${pin.state}. ${range.note}.` : viewSnapshot ? `Recorded view ${viewSnapshot.view}: lines ${start}–${end} of ${lines.length}. State ${viewSnapshot.state}. No working-copy bytes or before revision.` : `Recorded ${side}: lines ${start}–${end} of ${lines.length}. ${range.note}. ${snapshot.reviewed_root ? 'Selected source file.' : 'Caller context only, not an additional reviewed root.'}`; |
| 299 | } |
| 300 | update(); |
| 301 | return host; |
| 302 | } |
no test coverage detected