diff --git a/js/snapToGrid.js b/js/snapToGrid.js new file mode 100644 index 0000000..ab417a5 --- /dev/null +++ b/js/snapToGrid.js @@ -0,0 +1,27 @@ +import { app } from "/scripts/app.js"; + +const id = "pysssss.SnapToGrid"; +const ext = { + name: id, + async setup(app) { + app.ui.settings.addSetting({ + id, + name: "🐍 Always snap to grid", + defaultValue: false, + type: "boolean", + onChange(value) { + app.canvas.align_to_grid = value; + }, + }); + const origDrawNode = LGraphCanvas.prototype.drawNode; + LGraphCanvas.prototype.drawNode = function () { + const shift = app.shiftDown; + app.shiftDown = true; // Force it to draw the drop position + const r = origDrawNode.apply(this, arguments); + app.shiftDown = shift; + return r; + }; + }, +}; + +app.registerExtension(ext);