mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-11 05:52:33 +08:00
Restore context menu filter
This commit is contained in:
parent
99cf5bd67b
commit
229bd2765c
@ -1,5 +1,5 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { LiteGraph } from "../../lib/litegraph.core.js"
|
||||
import { LiteGraph, LGraphCanvas } from "../../lib/litegraph.core.js"
|
||||
import { hook } from "../../scripts/utils.js";
|
||||
|
||||
// Adds filtering to combo context menus
|
||||
@ -15,9 +15,9 @@ const ext = {
|
||||
const filter = document.createElement("input");
|
||||
filter.classList.add("comfy-context-menu-filter");
|
||||
filter.placeholder = "Filter list";
|
||||
this.root.prepend(filter);
|
||||
contextMenu.root.prepend(filter);
|
||||
|
||||
const items = Array.from(this.root.querySelectorAll(".litemenu-entry"));
|
||||
const items = Array.from(contextMenu.root.querySelectorAll(".litemenu-entry"));
|
||||
let displayedItems = [...items];
|
||||
let itemCount = displayedItems.length;
|
||||
|
||||
@ -25,8 +25,8 @@ const ext = {
|
||||
requestAnimationFrame(() => {
|
||||
const currentNode = LGraphCanvas.active_canvas.current_node;
|
||||
const clickedComboValue = currentNode.widgets
|
||||
.filter(w => w.type === "combo" && w.options.values.length === values.length)
|
||||
.find(w => w.options.values.every((v, i) => v === values[i]))
|
||||
.filter(w => w.type === "combo" && w.options.values.length === contextMenu.values.length)
|
||||
.find(w => w.options.values.every((v, i) => v === contextMenu.values[i]))
|
||||
?.value;
|
||||
|
||||
let selectedIndex = clickedComboValue ? contextMenu.values.findIndex(v => v === clickedComboValue) : 0;
|
||||
@ -46,13 +46,13 @@ const ext = {
|
||||
}
|
||||
|
||||
const positionList = () => {
|
||||
const rect = this.root.getBoundingClientRect();
|
||||
const rect = contextMenu.root.getBoundingClientRect();
|
||||
|
||||
// If the top is off-screen then shift the element with scaling applied
|
||||
if (rect.top < 0) {
|
||||
const scale = 1 - this.root.getBoundingClientRect().height / this.root.clientHeight;
|
||||
const shift = (this.root.clientHeight * scale) / 2;
|
||||
this.root.style.top = -shift + "px";
|
||||
const scale = 1 - contextMenu.root.getBoundingClientRect().height / contextMenu.root.clientHeight;
|
||||
const shift = (contextMenu.root.clientHeight * scale) / 2;
|
||||
contextMenu.root.style.top = -shift + "px";
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ const ext = {
|
||||
selectedItem?.click();
|
||||
break;
|
||||
case "Escape":
|
||||
this.close();
|
||||
contextMenu.close();
|
||||
break;
|
||||
}
|
||||
});
|
||||
@ -119,12 +119,12 @@ const ext = {
|
||||
let top = contextMenu.options.event.clientY - 10;
|
||||
|
||||
const bodyRect = document.body.getBoundingClientRect();
|
||||
const rootRect = this.root.getBoundingClientRect();
|
||||
const rootRect = contextMenu.root.getBoundingClientRect();
|
||||
if (bodyRect.height && top > bodyRect.height - rootRect.height - 10) {
|
||||
top = Math.max(0, bodyRect.height - rootRect.height - 10);
|
||||
}
|
||||
|
||||
this.root.style.top = top + "px";
|
||||
contextMenu.root.style.top = top + "px";
|
||||
positionList();
|
||||
}
|
||||
});
|
||||
|
||||
@ -3,8 +3,21 @@ export function range(size, startAt = 0) {
|
||||
}
|
||||
|
||||
export function hook(klass, fnName, cb) {
|
||||
const orig = location[fnName];
|
||||
location[fnName] = (...args) => {
|
||||
const fnLocation = klass;
|
||||
const orig = fnLocation[fnName];
|
||||
fnLocation[fnName] = (...args) => {
|
||||
cb(orig, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
const a = {
|
||||
b: (c, d, e) => {
|
||||
console.log(c, d, e);
|
||||
}
|
||||
}
|
||||
|
||||
a.b(1,2,3)
|
||||
hook(a, "b", (orig, c, d, e) => {
|
||||
orig(c, d, e);
|
||||
})
|
||||
a.b(1,2,3)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user