Skip to content

Commit c2ba6b0

Browse files
committed
Update the canvas detail view only when drawing is done
And remove the canvas from the view once it's destroyed.
1 parent 777251d commit c2ba6b0

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

web/internal/canvas_context_details_view.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ class CanvasContextDetailsView {
110110
this.#ctxStates.set(label, state);
111111
this.#ctxStateStacks.set(label, []);
112112
this.#ctxStackViewIdx.set(label, null);
113-
// If the panel is already visible (stepping in progress), rebuild it so
114-
// the new context section is added and its live-update entries are
115-
// registered.
116-
if (this.#gfxStateValueElements.size > 0) {
113+
// If the panel is already visible and we're at a pause point, rebuild it
114+
// so the new context section is added and its live-update entries are
115+
// registered. Skip the rebuild while frozen (execution is in progress
116+
// between pauses) — the next build() call from #onStepped() will pick it
117+
// up.
118+
if (!this.#frozen && this.#gfxStateValueElements.size > 0) {
117119
this.build();
118120
}
119121

@@ -303,9 +305,29 @@ class CanvasContextDetailsView {
303305
}
304306
}
305307

306-
/** Hide the panel. */
308+
/**
309+
* Remove the section for a single context from the panel and all internal
310+
* state maps. Called when a temporary canvas is destroyed.
311+
*/
312+
removeContext(label) {
313+
this.#ctxStates.delete(label);
314+
this.#ctxStateStacks.delete(label);
315+
this.#ctxStackViewIdx.delete(label);
316+
this.#gfxStateValueElements.delete(label);
317+
this.#gfxStateNavElements.delete(label);
318+
this.#panel
319+
.querySelector(
320+
`.gfx-state-section[data-ctx-label="${CSS.escape(label)}"]`
321+
)
322+
?.remove();
323+
}
324+
325+
/** Hide the panel and discard all DOM state so no live updates occur. */
307326
hide() {
308327
this.#panel.hidden = true;
328+
this.#gfxStateValueElements.clear();
329+
this.#gfxStateNavElements.clear();
330+
this.#panel.replaceChildren();
309331
}
310332

311333
/**

web/internal/page_view.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ class PageView {
355355
destroy(canvasAndCtx) {
356356
const idx = this.#alive.findIndex(e => e.canvasAndCtx === canvasAndCtx);
357357
if (idx !== -1) {
358-
this.#alive[idx].wrapper.remove();
358+
const { wrapper, ctxLabel } = this.#alive[idx];
359+
wrapper.remove();
360+
gfxStateComp.removeContext(ctxLabel);
359361
this.#alive.splice(idx, 1);
360362
}
361363
super.destroy(canvasAndCtx);
@@ -393,7 +395,7 @@ class PageView {
393395
checker.className = "canvas-checker";
394396
checker.append(canvasAndCtx.canvas);
395397
wrapper.append(labelEl, checker);
396-
const entry = { canvasAndCtx, wrapper, labelEl };
398+
const entry = { canvasAndCtx, wrapper, labelEl, ctxLabel };
397399
this.#alive.push(entry);
398400
this.#attachWrapper(entry);
399401
}
@@ -482,7 +484,10 @@ class PageView {
482484
});
483485

484486
this.#stepButton.addEventListener("click", () => {
485-
globalThis.StepperManager._active?.stepNext();
487+
if (globalThis.StepperManager._active) {
488+
this.#gfxStateComp.freeze();
489+
globalThis.StepperManager._active.stepNext();
490+
}
486491
});
487492

488493
this.#continueButton.addEventListener("click", () => {
@@ -580,9 +585,11 @@ class PageView {
580585
}
581586
if (e.key === "s") {
582587
e.preventDefault();
588+
this.#gfxStateComp.freeze();
583589
stepper.stepNext();
584590
} else if (e.key === "c") {
585591
e.preventDefault();
592+
this.#gfxStateComp.freeze();
586593
stepper.continueToBreakpoint();
587594
}
588595
});

0 commit comments

Comments
 (0)