Add reset view button

Prevent view changes causing history entries
This commit is contained in:
pythongosssss 2024-05-13 17:17:20 +01:00
parent 5f90d132e7
commit 16ba362746
4 changed files with 18 additions and 7 deletions

View File

@ -44,7 +44,7 @@ export class ChangeTracker {
} }
checkState() { checkState() {
if(!this.app.graph) return; if (!this.app.graph) return;
const currentState = this.app.graph.serialize(); const currentState = this.app.graph.serialize();
if (!this.activeState) { if (!this.activeState) {
@ -173,8 +173,8 @@ export class ChangeTracker {
// Store node outputs // Store node outputs
api.addEventListener("executed", ({ detail }) => { api.addEventListener("executed", ({ detail }) => {
const prompt = app.workflowManager.queuedPrompts[detail.prompt_id]; const prompt = app.workflowManager.queuedPrompts[detail.prompt_id];
if(!prompt.workflow) return; if (!prompt.workflow) return;
const nodeOutputs = prompt.workflow.changeTracker.nodeOutputs ??= {}; const nodeOutputs = (prompt.workflow.changeTracker.nodeOutputs ??= {});
const output = nodeOutputs[detail.node]; const output = nodeOutputs[detail.node];
if (detail.merge && output) { if (detail.merge && output) {
for (const k in detail.output ?? {}) { for (const k in detail.output ?? {}) {
@ -206,7 +206,7 @@ export class ChangeTracker {
} }
} }
static graphEqual(a, b, root = true) { static graphEqual(a, b, path = "") {
if (a === b) return true; if (a === b) return true;
if (typeof a == "object" && a && typeof b == "object" && b) { if (typeof a == "object" && a && typeof b == "object" && b) {
@ -219,12 +219,15 @@ export class ChangeTracker {
for (const key of keys) { for (const key of keys) {
let av = a[key]; let av = a[key];
let bv = b[key]; let bv = b[key];
if (root && key === "nodes") { if (!path && key === "nodes") {
// Nodes need to be sorted as the order changes when selecting nodes // Nodes need to be sorted as the order changes when selecting nodes
av = [...av].sort((a, b) => a.id - b.id); av = [...av].sort((a, b) => a.id - b.id);
bv = [...bv].sort((a, b) => a.id - b.id); bv = [...bv].sort((a, b) => a.id - b.id);
} else if (path === "extra.ds") {
// Ignore view changes
continue;
} }
if (!ChangeTracker.graphEqual(av, bv, false)) { if (!ChangeTracker.graphEqual(av, bv, path + (path ? "." : "") + key)) {
return false; return false;
} }
} }

View File

@ -599,6 +599,7 @@ export class ComfyUI {
onclick: () => app.refreshComboInNodes() onclick: () => app.refreshComboInNodes()
}), }),
$el("button", {id: "comfy-clipspace-button", textContent: "Clipspace", onclick: () => app.openClipspace()}), $el("button", {id: "comfy-clipspace-button", textContent: "Clipspace", onclick: () => app.openClipspace()}),
$el("button", {id: "comfy-reset-view-button", textContent: "Reset View", onclick: () => app.resetView()}),
$el("button", { $el("button", {
id: "comfy-clear-button", textContent: "Clear", onclick: () => { id: "comfy-clear-button", textContent: "Clear", onclick: () => {
if (!confirmClear.value || confirm("Clear workflow?")) { if (!confirmClear.value || confirm("Clear workflow?")) {

View File

@ -77,6 +77,12 @@ export class ComfyAppMenu {
tooltip: "Open Clipspace window", tooltip: "Open Clipspace window",
action: () => app["openClipspace"](), action: () => app["openClipspace"](),
}), }),
new ComfyButton({
icon: "fit-to-page-outline",
content: "Reset View",
tooltip: "Reset the canvas view",
action: () => app.resetView()
}),
new ComfyButton({ new ComfyButton({
icon: "cancel", icon: "cancel",
content: "Clear", content: "Clear",

View File

@ -284,6 +284,7 @@ export class ComfyWorkflowsContent {
action: () => { action: () => {
popup.open = false; popup.open = false;
app.loadGraphData(); app.loadGraphData();
app.resetView();
}, },
}).element, }).element,
new ComfyButton({ new ComfyButton({