Ensures weird LiteGraph submenu calling also calls extensions' overrides. Fixes #369 and #417

This commit is contained in:
rgthree
2025-02-17 18:37:26 -05:00
parent 5d771b8b56
commit 31b784bac4
2 changed files with 17 additions and 5 deletions
+12 -3
View File
@@ -135,9 +135,18 @@ app.registerExtension({
if (options.scale == null) {
options.scale = Math.max(app.canvas.ds?.scale || 1, 1);
}
return existingContextMenu.call(this as any, values, options);
};
LiteGraph.ContextMenu.prototype = existingContextMenu.prototype;
const oldCtrResponse = existingContextMenu.call(this as any, values, options);
// For some reason, LiteGraph calls submenus with "this.constructor" which no longer allows
// us to continue building deep nesting, as well as skips many other extensions (even
// ComfyUI's core extensions like translations) from working on submenus. It also removes
// search, etc. While this is a recent-ish issue, I can't seem to find the culpit as it looks
// like old litegraph always did this. Perhaps changing it to a Class? Anyway, this fixes it;
// Hopefully without issues.
if ((oldCtrResponse as any)?.constructor) {
(oldCtrResponse as any).constructor = LiteGraph.ContextMenu;
}
return this;
};
},
});
+5 -2
View File
@@ -103,8 +103,11 @@ app.registerExtension({
if (options.scale == null) {
options.scale = Math.max(((_f = app.canvas.ds) === null || _f === void 0 ? void 0 : _f.scale) || 1, 1);
}
return existingContextMenu.call(this, values, options);
const oldCtrResponse = existingContextMenu.call(this, values, options);
if (oldCtrResponse === null || oldCtrResponse === void 0 ? void 0 : oldCtrResponse.constructor) {
oldCtrResponse.constructor = LiteGraph.ContextMenu;
}
return this;
};
LiteGraph.ContextMenu.prototype = existingContextMenu.prototype;
},
});