diff --git a/follow-execution/followExecution.js b/follow-execution/followExecution.js new file mode 100644 index 0000000..4072110 --- /dev/null +++ b/follow-execution/followExecution.js @@ -0,0 +1,35 @@ +import { app } from "/scripts/app.js"; +import { api } from "/scripts/api.js"; + +// Adds a menu option to toggle follow the executing node + +app.registerExtension({ + name: "pysssss.FollowExecution", + setup() { + let followExecution = false; + + const centerNode = (id) => { + if (!followExecution || !id) return; + const node = app.graph.getNodeById(id); + if (!node) return; + app.canvas.centerOnNode(node); + }; + + api.addEventListener("executing", ({ detail }) => centerNode(detail)); + + // Add canvas menu options + const orig = LGraphCanvas.prototype.getCanvasMenuOptions; + LGraphCanvas.prototype.getCanvasMenuOptions = function () { + const options = orig.apply(this, arguments); + options.push(null, { + content: followExecution ? "Stop following execution" : "Follow execution", + callback: () => { + if ((followExecution = !followExecution)) { + centerNode(app.runningNodeId); + } + }, + }); + return options; + }; + }, +});