mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 10:25:16 +00:00
Add left/right/escape hotkeys for image nodes
This commit is contained in:
parent
0d972b85e6
commit
bf7dbe4702
@ -102,6 +102,46 @@ class ComfyApp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#addNodeKeyHandler(node) {
|
||||||
|
const app = this;
|
||||||
|
const origNodeOnKeyDown = node.prototype.onKeyDown;
|
||||||
|
|
||||||
|
node.prototype.onKeyDown = function(e) {
|
||||||
|
if (origNodeOnKeyDown && origNodeOnKeyDown.apply(this, e) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.flags.collapsed || !this.imgs || this.imageIndex === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let handled = false;
|
||||||
|
|
||||||
|
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
||||||
|
if (e.key === "ArrowLeft") {
|
||||||
|
this.imageIndex -= 1;
|
||||||
|
} else if (e.key === "ArrowRight") {
|
||||||
|
this.imageIndex += 1;
|
||||||
|
}
|
||||||
|
this.imageIndex %= this.imgs.length;
|
||||||
|
|
||||||
|
if (this.imageIndex < 0) {
|
||||||
|
this.imageIndex = this.imgs.length + this.imageIndex;
|
||||||
|
}
|
||||||
|
handled = true;
|
||||||
|
} else if (e.key === "Escape") {
|
||||||
|
this.imageIndex = null;
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handled === true) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds Custom drawing logic for nodes
|
* Adds Custom drawing logic for nodes
|
||||||
* e.g. Draws images and handles thumbnail navigation on nodes that output images
|
* e.g. Draws images and handles thumbnail navigation on nodes that output images
|
||||||
@ -785,6 +825,7 @@ class ComfyApp {
|
|||||||
|
|
||||||
this.#addNodeContextMenuHandler(node);
|
this.#addNodeContextMenuHandler(node);
|
||||||
this.#addDrawBackgroundHandler(node, app);
|
this.#addDrawBackgroundHandler(node, app);
|
||||||
|
this.#addNodeKeyHandler(node);
|
||||||
|
|
||||||
await this.#invokeExtensionsAsync("beforeRegisterNodeDef", node, nodeData);
|
await this.#invokeExtensionsAsync("beforeRegisterNodeDef", node, nodeData);
|
||||||
LiteGraph.registerNodeType(nodeId, node);
|
LiteGraph.registerNodeType(nodeId, node);
|
||||||
|
Loading…
Reference in New Issue
Block a user