Compare commits
2 Commits
6c2afb1cbb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6648d4b9d6 | |||
| caab0a4eeb |
+35
-23
@@ -1778,9 +1778,10 @@ async function restoreSnapshot(record) {
|
|||||||
if (!full) { showToast("Failed to load snapshot data", "error"); return; }
|
if (!full) { showToast("Failed to load snapshot data", "error"); return; }
|
||||||
record = full;
|
record = full;
|
||||||
}
|
}
|
||||||
// Preserve any unsaved live edits before replacing the canvas (parity with
|
// Preserve any unsaved meaningful edit before replacing the canvas (parity
|
||||||
// swap). Deduped by hash, so it's a no-op when there is nothing new to save.
|
// with swap). Deduped by hash and skips cosmetic-only changes, so it's a
|
||||||
await captureSnapshot("Current").catch(() => {});
|
// no-op when there is nothing meaningful new to save.
|
||||||
|
await captureSnapshot("Current", { skipCosmetic: true }).catch(() => {});
|
||||||
await withRestoreLock(async () => {
|
await withRestoreLock(async () => {
|
||||||
if (!validateSnapshotData(record.graphData)) {
|
if (!validateSnapshotData(record.graphData)) {
|
||||||
showToast("Invalid snapshot data", "error");
|
showToast("Invalid snapshot data", "error");
|
||||||
@@ -1789,8 +1790,13 @@ async function restoreSnapshot(record) {
|
|||||||
try {
|
try {
|
||||||
await app.loadGraphData(record.graphData, true, true);
|
await app.loadGraphData(record.graphData, true, true);
|
||||||
const wfKey = getWorkflowKey();
|
const wfKey = getWorkflowKey();
|
||||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(record.graphData)));
|
// Seed the dedup baseline from the LIVE re-serialization, not the
|
||||||
setLastGraphData(wfKey, record.graphData);
|
// stored record: ComfyUI's serialize() of the loaded graph isn't
|
||||||
|
// byte-identical to the saved bytes, so seeding from record.graphData
|
||||||
|
// makes the next captureSnapshot() hash mismatch and spuriously save.
|
||||||
|
const liveGraph = getGraphData() || record.graphData;
|
||||||
|
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(liveGraph)));
|
||||||
|
setLastGraphData(wfKey, liveGraph);
|
||||||
showToast("Snapshot restored", "success");
|
showToast("Snapshot restored", "success");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`[${EXTENSION_NAME}] Restore failed:`, err);
|
console.warn(`[${EXTENSION_NAME}] Restore failed:`, err);
|
||||||
@@ -1814,8 +1820,11 @@ async function swapSnapshot(record, { quiet = false } = {}) {
|
|||||||
// between already-saved snapshots, but it WILL save any unsaved live edits
|
// between already-saved snapshots, but it WILL save any unsaved live edits
|
||||||
// made after a previous swap (when activeSnapshotId is still set) — which
|
// made after a previous swap (when activeSnapshotId is still set) — which
|
||||||
// would otherwise be silently discarded by the load below.
|
// would otherwise be silently discarded by the load below.
|
||||||
|
// Preserve a genuine unsaved edit before loading, but skip cosmetic-only
|
||||||
|
// changes (move/resize/collapse) and dedup no-ops so that merely browsing
|
||||||
|
// between snapshots never spawns a "Current" snapshot (the reported spam).
|
||||||
const prevCurrentId = currentSnapshotId;
|
const prevCurrentId = currentSnapshotId;
|
||||||
const capturedId = await captureSnapshot("Current");
|
const capturedId = await captureSnapshot("Current", { skipCosmetic: true });
|
||||||
currentSnapshotId = capturedId || prevCurrentId;
|
currentSnapshotId = capturedId || prevCurrentId;
|
||||||
|
|
||||||
if (!record.graphData) {
|
if (!record.graphData) {
|
||||||
@@ -1833,8 +1842,14 @@ async function swapSnapshot(record, { quiet = false } = {}) {
|
|||||||
const workflow = app.extensionManager?.workflow?.activeWorkflow;
|
const workflow = app.extensionManager?.workflow?.activeWorkflow;
|
||||||
await app.loadGraphData(record.graphData, true, true, workflow);
|
await app.loadGraphData(record.graphData, true, true, workflow);
|
||||||
const wfKey = getWorkflowKey();
|
const wfKey = getWorkflowKey();
|
||||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(record.graphData)));
|
// Seed the dedup baseline from the LIVE re-serialization, not the
|
||||||
setLastGraphData(wfKey, record.graphData);
|
// stored record: ComfyUI's serialize() of the loaded graph isn't
|
||||||
|
// byte-identical to the saved bytes, so seeding from record.graphData
|
||||||
|
// makes the next captureSnapshot() hash mismatch and spuriously save a
|
||||||
|
// "Current" snapshot on every swap (the reported timeline-swap spam).
|
||||||
|
const liveGraph = getGraphData() || record.graphData;
|
||||||
|
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(liveGraph)));
|
||||||
|
setLastGraphData(wfKey, liveGraph);
|
||||||
activeSnapshotId = record.id;
|
activeSnapshotId = record.id;
|
||||||
if (!quiet) showToast("Snapshot swapped", "success");
|
if (!quiet) showToast("Snapshot swapped", "success");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -4396,12 +4411,16 @@ if (window.__COMFYUI_FRONTEND_VERSION__) {
|
|||||||
activeBranchSelections.clear();
|
activeBranchSelections.clear();
|
||||||
// Seed active ring for the new workflow tab
|
// Seed active ring for the new workflow tab
|
||||||
const newKey = getWorkflowKey();
|
const newKey = getWorkflowKey();
|
||||||
// Re-seed the dedup/change-detection baseline for the new
|
// Suppress auto-capture briefly so the graphChanged fired
|
||||||
// tab and suppress auto-capture briefly, so the graphChanged
|
// by loading this workflow doesn't spawn a redundant "Auto"
|
||||||
// fired by loading this workflow doesn't spawn a redundant
|
// snapshot of a workflow the user only just opened. Guard
|
||||||
// "Auto" snapshot of a workflow the user only just opened.
|
// everything so a failure here can never break the switch.
|
||||||
seedWorkflowBaseline(newKey);
|
try {
|
||||||
suppressAutoCapture(SWITCH_GUARD_MS);
|
suppressAutoCapture(SWITCH_GUARD_MS);
|
||||||
|
seedWorkflowBaseline(newKey);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`[${EXTENSION_NAME}] post-switch seeding failed:`, err);
|
||||||
|
}
|
||||||
trackSessionWorkflow(newKey);
|
trackSessionWorkflow(newKey);
|
||||||
db_getAllForWorkflow(newKey).then(recs => {
|
db_getAllForWorkflow(newKey).then(recs => {
|
||||||
if (recs.length > 0 && !lastCapturedIdMap.has(newKey)) {
|
if (recs.length > 0 && !lastCapturedIdMap.has(newKey)) {
|
||||||
@@ -4436,16 +4455,9 @@ if (window.__COMFYUI_FRONTEND_VERSION__) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Alt+Left / Alt+Right step non-destructively through snapshot history
|
// (Keyboard step-navigation removed: a global Alt+Left/Right handler
|
||||||
// (Fusion-360 "roll the history marker" feel — jump back/forth freely).
|
// collides with the browser's Back/Forward. stepToSnapshot() remains
|
||||||
document.addEventListener("keydown", (e) => {
|
// for a future, conflict-free binding or a timeline button.)
|
||||||
if (!e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
||||||
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
|
||||||
const t = e.target;
|
|
||||||
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
|
|
||||||
e.preventDefault();
|
|
||||||
stepToSnapshot(e.key === "ArrowLeft" ? -1 : 1).catch(() => {});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build the timeline bar on the canvas
|
// Build the timeline bar on the canvas
|
||||||
buildTimeline();
|
buildTimeline();
|
||||||
|
|||||||
Reference in New Issue
Block a user