fix: preserve block editor state on save
Template tests / tests (push) Successful in 1m41s

This commit is contained in:
2026-06-13 15:51:23 -05:00
parent 2274544ed8
commit 20d69619c2
+31 -9
View File
@@ -1101,9 +1101,7 @@ class GuideEditor {
size: record.image.size, size: record.image.size,
step, step,
}); });
this.stepMap.set(saved.stepId, saved); this.commitSavedStep(saved);
const idx = this.steps.findIndex((s) => s.stepId === saved.stepId);
if (idx >= 0) this.steps[idx] = saved;
} else { } else {
await this.flushStep(step); await this.flushStep(step);
} }
@@ -1139,14 +1137,11 @@ class GuideEditor {
if (!step) return; if (!step) return;
this.pendingSave = false; this.pendingSave = false;
const saved = await api.step.save({ guideId: this.guideId, step }); const saved = await api.step.save({ guideId: this.guideId, step });
this.stepMap.set(saved.stepId, saved); const committed = this.commitSavedStep(saved);
// Keep the steps array in sync — it holds the objects the list renders. if (this.selectedStepId === committed.stepId) {
const idx = this.steps.findIndex((s) => s.stepId === saved.stepId);
if (idx >= 0) this.steps[idx] = saved;
if (this.selectedStepId === saved.stepId) {
this.renderStepList(); this.renderStepList();
this.syncStepFields(); this.syncStepFields();
this.canvas.setAnnotations(saved.annotations || []); this.canvas.setAnnotations(committed.annotations || []);
// Rebuilding the annotation editor while the user is typing in one of // Rebuilding the annotation editor while the user is typing in one of
// its inputs would steal focus, so skip it in that case. // its inputs would steal focus, so skip it in that case.
if (!this.dom.annotationEditor.contains(document.activeElement)) { if (!this.dom.annotationEditor.contains(document.activeElement)) {
@@ -1154,9 +1149,36 @@ class GuideEditor {
} }
this.emitMeta(); this.emitMeta();
} }
return committed;
}
commitSavedStep(saved) {
if (!saved || !saved.stepId) return saved;
const existing = this.stepMap.get(saved.stepId);
if (!existing || existing === saved) {
this.stepMap.set(saved.stepId, saved);
const idx = this.steps.findIndex((s) => s.stepId === saved.stepId);
if (idx >= 0) this.steps[idx] = saved;
return saved; return saved;
} }
// Keep the live block arrays so block-card closures keep pointing at the
// same objects after the backend returns a fresh saved step.
const preservedBlocks = {
textBlocks: existing.textBlocks,
codeBlocks: existing.codeBlocks,
tableBlocks: existing.tableBlocks,
};
for (const key of Object.keys(existing)) {
if (!(key in saved)) delete existing[key];
}
Object.assign(existing, saved, preservedBlocks);
this.stepMap.set(existing.stepId, existing);
const idx = this.steps.findIndex((s) => s.stepId === existing.stepId);
if (idx >= 0) this.steps[idx] = existing;
return existing;
}
async flushGuide() { async flushGuide() {
if (!this.guide) return; if (!this.guide) return;
this.pendingGuideSave = false; this.pendingGuideSave = false;