Editor: materialize a just-typed global prompt before generate (screen = truth)

Root of the 'same video despite a different prompt' bug: editing the global
prompt is debounced 500ms (scheduleGlobalPromptApply) before it distributes
into scene.text. Hit Generate within that window ('thought runs faster than
quicksave') and _flushSaveForGenerate saved the OLD scene text while the screen
showed the new prompt — so generation (which reads the saved scenes) used stale
text, persisted, and survived restart.

Track the latest typed global prompt and add flushGlobalPromptApply(); call it at
the top of _flushSaveForGenerate so any pending global-prompt edit is distributed
into scenes (which also reconciles ghosts via _alignScenesFromParsed) BEFORE save
and generate. The file stays a faithful snapshot of the screen at generate time.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
digital-garbage
2026-06-15 13:03:46 +03:00
co-authored by Claude Opus 4.8
parent 2fae920839
commit d79463a5ca
+16 -1
View File
@@ -221,13 +221,27 @@
}
let _globalApplyTimer = null;
let _pendingGlobalPromptText = null; // latest typed global prompt awaiting distribution
function scheduleGlobalPromptApply(text) {
_pendingGlobalPromptText = text;
clearTimeout(_globalApplyTimer);
_globalApplyTimer = setTimeout(() => {
applyGlobalPromptQuiet(text).catch((e) => console.warn("Global prompt apply failed:", e));
_globalApplyTimer = null;
const t = _pendingGlobalPromptText; _pendingGlobalPromptText = null;
applyGlobalPromptQuiet(t).catch((e) => console.warn("Global prompt apply failed:", e));
}, 500);
}
// Materialize a still-debounced global-prompt edit into scene.text NOW (screen = truth). Called
// before generate/save so a prompt typed faster than the 500ms debounce isn't left undistributed
// — otherwise we'd save (and generate from) stale scene text while the screen shows the new prompt.
async function flushGlobalPromptApply() {
if (_globalApplyTimer) { clearTimeout(_globalApplyTimer); _globalApplyTimer = null; }
if (_pendingGlobalPromptText == null) return;
const t = _pendingGlobalPromptText; _pendingGlobalPromptText = null;
await applyGlobalPromptQuiet(t);
}
function _normalizeSceneText(t) {
return String(t || "").trim().replace(/\s+/g, " ");
}
@@ -2371,6 +2385,7 @@
}
async function _flushSaveForGenerate() {
await flushGlobalPromptApply(); // distribute any just-typed global prompt into scenes first
await flushSave();
if (_localDirty) {
throw new Error(