Compare commits
6 Commits
78b1b85a11
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 690278b592 | |||
| 3ee14819b7 | |||
| d6d2c98a58 | |||
| 36dd5c91ee | |||
| 954b9ec2e6 | |||
| 1881aa727f |
+27
-9
@@ -32,7 +32,9 @@ const MARGIN = 10; // ComfyUI DOM-widget inset, matches the other nodes
|
||||
// `protected` (BOOLEAN toggle) + `stored_text` (hidden STRING) are real backend
|
||||
// widgets. When protected, the node acts as a plain text node: it outputs
|
||||
// stored_text and ignores upstream (no pause). The DOM textarea is the visible
|
||||
// editor and mirrors its value into stored_text so it persists and reaches run().
|
||||
// editor and mirrors its value into stored_text on EVERY change (typing, upstream
|
||||
// arrival, Pass) — so the editor content survives refresh / workflow reload in
|
||||
// BOTH modes (stored_text also reaches run() when protected).
|
||||
|
||||
function widgetByName(node, name) {
|
||||
return node.widgets?.find((w) => w.name === name);
|
||||
@@ -59,15 +61,13 @@ function hideStoredWidget(node) {
|
||||
w.computeSize = () => [0, -4];
|
||||
}
|
||||
|
||||
// reflect the persisted protected/stored_text state into the editor + UI
|
||||
// reflect the persisted stored_text + mode into the editor + UI. The editor text
|
||||
// is restored in BOTH modes so it survives a refresh / workflow reload; the mode
|
||||
// only selects the UI state (protected vs idle waiting-for-a-run).
|
||||
function applyPersistedMode(node) {
|
||||
if (!node._tg) return;
|
||||
if (isProtected(node)) {
|
||||
node._tg.area.value = widgetByName(node, "stored_text")?.value ?? "";
|
||||
setState(node, "protected");
|
||||
} else {
|
||||
setState(node, "idle");
|
||||
}
|
||||
setState(node, isProtected(node) ? "protected" : "idle");
|
||||
}
|
||||
|
||||
// ---- server call ------------------------------------------------------------
|
||||
@@ -170,8 +170,17 @@ function setupTextGateNode(node) {
|
||||
const area = document.createElement("textarea");
|
||||
area.className = "tgate-area";
|
||||
area.placeholder = "waiting for a run…";
|
||||
// don't let typing/space toggle node selection or graph shortcuts
|
||||
area.onkeydown = (e) => e.stopPropagation();
|
||||
// Stop keys from reaching litegraph (so typing/space can't toggle node
|
||||
// selection or fire canvas shortcuts) — EXCEPT ComfyUI's prompt-weighting
|
||||
// shortcut (Ctrl/Cmd+↑/↓). That handler is a global `window` keydown listener
|
||||
// that wraps the selection in (token:weight); a blanket stopPropagation here
|
||||
// kept it from ever bubbling up, so weighting didn't work in this editor.
|
||||
// Its execCommand edit fires our oninput, so the weighted text still syncs.
|
||||
area.onkeydown = (e) => {
|
||||
const isWeight = (e.ctrlKey || e.metaKey) &&
|
||||
(e.key === "ArrowUp" || e.key === "ArrowDown");
|
||||
if (!isWeight) e.stopPropagation();
|
||||
};
|
||||
// keep the hidden stored_text widget mirrored so edits persist + reach run()
|
||||
area.oninput = () => syncStored(node);
|
||||
|
||||
@@ -182,6 +191,7 @@ function setupTextGateNode(node) {
|
||||
pass.className = "tgate-pass";
|
||||
pass.textContent = "▶ Pass";
|
||||
pass.onclick = async () => {
|
||||
syncStored(node); // persist the passed text so a reload keeps it
|
||||
await postPass(node, area.value);
|
||||
setState(node, "passed");
|
||||
};
|
||||
@@ -245,11 +255,18 @@ function setupTextGateNode(node) {
|
||||
syncWidgetWidth(node);
|
||||
}
|
||||
|
||||
// Build marker — lets you confirm the browser loaded THIS build (not a cached
|
||||
// old copy). If the editor comes back empty after reload but you don't see this
|
||||
// line in the devtools console, your tab is running stale JS: hard-refresh
|
||||
// (Ctrl/Cmd+Shift+R).
|
||||
const BUILD = "2026-07-03 persist+weight";
|
||||
|
||||
app.registerExtension({
|
||||
name: "datasete.gates.textgate",
|
||||
|
||||
// one global socket listener: route the server's pause event to the node
|
||||
setup() {
|
||||
console.info(`[datasete.textgate] loaded build ${BUILD}`);
|
||||
api.addEventListener("datasete-textgate-show", (e) => {
|
||||
const d = e.detail || {};
|
||||
const node = app.graph?.getNodeById?.(parseInt(d.id, 10));
|
||||
@@ -265,6 +282,7 @@ app.registerExtension({
|
||||
} else {
|
||||
node._tg.area.value = d.text || "";
|
||||
}
|
||||
syncStored(node); // persist the shown text so a refresh/reload keeps it
|
||||
setState(node, "paused");
|
||||
try { node._tg.area.focus(); } catch (err) { /* ignore */ }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user