mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +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 { 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";
|
import { hook } from "../../scripts/utils.js";
|
||||||
|
|
||||||
// Adds filtering to combo context menus
|
// Adds filtering to combo context menus
|
||||||
@ -15,9 +15,9 @@ const ext = {
|
|||||||
const filter = document.createElement("input");
|
const filter = document.createElement("input");
|
||||||
filter.classList.add("comfy-context-menu-filter");
|
filter.classList.add("comfy-context-menu-filter");
|
||||||
filter.placeholder = "Filter list";
|
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 displayedItems = [...items];
|
||||||
let itemCount = displayedItems.length;
|
let itemCount = displayedItems.length;
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ const ext = {
|
|||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const currentNode = LGraphCanvas.active_canvas.current_node;
|
const currentNode = LGraphCanvas.active_canvas.current_node;
|
||||||
const clickedComboValue = currentNode.widgets
|
const clickedComboValue = currentNode.widgets
|
||||||
.filter(w => w.type === "combo" && w.options.values.length === values.length)
|
.filter(w => w.type === "combo" && w.options.values.length === contextMenu.values.length)
|
||||||
.find(w => w.options.values.every((v, i) => v === values[i]))
|
.find(w => w.options.values.every((v, i) => v === contextMenu.values[i]))
|
||||||
?.value;
|
?.value;
|
||||||
|
|
||||||
let selectedIndex = clickedComboValue ? contextMenu.values.findIndex(v => v === clickedComboValue) : 0;
|
let selectedIndex = clickedComboValue ? contextMenu.values.findIndex(v => v === clickedComboValue) : 0;
|
||||||
@ -46,13 +46,13 @@ const ext = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const positionList = () => {
|
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 the top is off-screen then shift the element with scaling applied
|
||||||
if (rect.top < 0) {
|
if (rect.top < 0) {
|
||||||
const scale = 1 - this.root.getBoundingClientRect().height / this.root.clientHeight;
|
const scale = 1 - contextMenu.root.getBoundingClientRect().height / contextMenu.root.clientHeight;
|
||||||
const shift = (this.root.clientHeight * scale) / 2;
|
const shift = (contextMenu.root.clientHeight * scale) / 2;
|
||||||
this.root.style.top = -shift + "px";
|
contextMenu.root.style.top = -shift + "px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ const ext = {
|
|||||||
selectedItem?.click();
|
selectedItem?.click();
|
||||||
break;
|
break;
|
||||||
case "Escape":
|
case "Escape":
|
||||||
this.close();
|
contextMenu.close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -119,12 +119,12 @@ const ext = {
|
|||||||
let top = contextMenu.options.event.clientY - 10;
|
let top = contextMenu.options.event.clientY - 10;
|
||||||
|
|
||||||
const bodyRect = document.body.getBoundingClientRect();
|
const bodyRect = document.body.getBoundingClientRect();
|
||||||
const rootRect = this.root.getBoundingClientRect();
|
const rootRect = contextMenu.root.getBoundingClientRect();
|
||||||
if (bodyRect.height && top > bodyRect.height - rootRect.height - 10) {
|
if (bodyRect.height && top > bodyRect.height - rootRect.height - 10) {
|
||||||
top = Math.max(0, 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();
|
positionList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,8 +3,21 @@ export function range(size, startAt = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function hook(klass, fnName, cb) {
|
export function hook(klass, fnName, cb) {
|
||||||
const orig = location[fnName];
|
const fnLocation = klass;
|
||||||
location[fnName] = (...args) => {
|
const orig = fnLocation[fnName];
|
||||||
|
fnLocation[fnName] = (...args) => {
|
||||||
cb(orig, ...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