From 7e9ab75c5a21172d069509643a775791785486f9 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sun, 23 Apr 2023 18:37:33 +0100 Subject: [PATCH] Adds menu option to follow the executing node --- follow-execution/followExecution.js | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 follow-execution/followExecution.js 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; + }; + }, +});