prompts: undo experiment, update system
This commit is contained in:
@@ -38,9 +38,6 @@ export class TranscriptContainer extends Container {
|
||||
// Bumped to invalidate every block's snapshot at once; a snapshot is only
|
||||
// honored when its stored generation still matches.
|
||||
#generation = 0;
|
||||
#lastRenderWidth = 0;
|
||||
#lastChildLineCounts: number[] = [];
|
||||
#lastChildStableCounts: number[] = [];
|
||||
|
||||
override invalidate(): void {
|
||||
// A theme/global invalidation forces a full recompute on the rebuild that
|
||||
@@ -66,52 +63,29 @@ export class TranscriptContainer extends Container {
|
||||
|
||||
override render(width: number): string[] {
|
||||
width = Math.max(1, width);
|
||||
if (!TERMINAL.eagerEraseScrollbackRisk) return super.render(width);
|
||||
|
||||
const lines: string[] = [];
|
||||
const counts: number[] = [];
|
||||
const stableCounts: number[] = [];
|
||||
const liveIndex = this.children.length - 1;
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
const child = this.children[i]! as Component & SnapshotCarrier;
|
||||
let rendered: string[] | undefined;
|
||||
if (TERMINAL.eagerEraseScrollbackRisk && i !== liveIndex) {
|
||||
if (i !== liveIndex) {
|
||||
const snapshot = child[kSnapshot];
|
||||
// Replay the block's last render from while it was live. A stale
|
||||
// generation (post-thaw) or width mismatch (resize in flight, an
|
||||
// explicit rebuild that reconciles history anyway) recomputes instead.
|
||||
if (snapshot && snapshot.generation === this.#generation && snapshot.width === width) {
|
||||
rendered = snapshot.lines;
|
||||
lines.push(...snapshot.lines);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
rendered ??= child.render(width);
|
||||
if (TERMINAL.eagerEraseScrollbackRisk) {
|
||||
// Cache every block's latest render. While a block is live this keeps
|
||||
// its snapshot current; the frame it stops being live the cache already
|
||||
// holds its final live render, so nothing recomputes underneath it.
|
||||
child[kSnapshot] = { width, lines: rendered, generation: this.#generation };
|
||||
}
|
||||
const stable = i === liveIndex ? (child.getStableLineCount?.(width) ?? 0) : rendered.length;
|
||||
counts.push(rendered.length);
|
||||
stableCounts.push(Math.max(0, Math.min(rendered.length, stable)));
|
||||
const rendered = child.render(width);
|
||||
// Cache every block's latest render. While a block is live this keeps its
|
||||
// snapshot current; the frame it stops being live the cache already holds
|
||||
// its final live render, so nothing recomputes underneath it.
|
||||
child[kSnapshot] = { width, lines: rendered, generation: this.#generation };
|
||||
lines.push(...rendered);
|
||||
}
|
||||
this.#lastRenderWidth = width;
|
||||
this.#lastChildLineCounts = counts;
|
||||
this.#lastChildStableCounts = stableCounts;
|
||||
return lines;
|
||||
}
|
||||
|
||||
getStableLineCount(width: number): number {
|
||||
if (this.#lastRenderWidth !== Math.max(1, width) || this.#lastChildLineCounts.length !== this.children.length) {
|
||||
return 0;
|
||||
}
|
||||
let stable = 0;
|
||||
for (let i = 0; i < this.#lastChildLineCounts.length; i++) {
|
||||
const length = this.#lastChildLineCounts[i] ?? 0;
|
||||
const childStable = this.#lastChildStableCounts[i] ?? 0;
|
||||
stable += childStable;
|
||||
if (childStable < length) break;
|
||||
}
|
||||
return stable;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user