Skip to content

Commit 0e7d41c

Browse files
committed
Add sorting by display name.
1 parent 0816d20 commit 0e7d41c

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src_web/comfyui/power_lora_loader.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
134134

135135
override getExtraMenuOptions(canvas: LGraphCanvas, options: ContextMenuItem[]): void {
136136
super.getExtraMenuOptions?.apply(this, [...arguments] as any);
137-
const fetchInfoMenuItem = {
137+
const fetchInfoMenuItem: ContextMenuItem = {
138138
content: "Fetch info for all LoRAs",
139139
callback: (
140140
_value: ContextMenuItem,
@@ -154,7 +154,7 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
154154
});
155155
},
156156
};
157-
const fixPathsMenuItem = {
157+
const fixPathsMenuItem: ContextMenuItem = {
158158
content: "Update paths for all LoRAs",
159159
callback: (
160160
_value: ContextMenuItem,
@@ -189,7 +189,22 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
189189
});
190190
},
191191
};
192-
options.splice(options.length - 1, 0, fetchInfoMenuItem, fixPathsMenuItem);
192+
const sortLoraWidgetsMenuItem: ContextMenuItem = {
193+
content: "Sort LoRA widgets by name",
194+
callback: (
195+
_value: ContextMenuItem,
196+
_options: IContextMenuOptions,
197+
_event: MouseEvent,
198+
_parentMenu: ContextMenu | undefined,
199+
_node: TLGraphNode,
200+
) => {
201+
const loraWidgets = this.getLoraWidgets();
202+
const sortedWidgets = loraWidgets.toSorted((a, b) => a.getLoraLabel().localeCompare(b.getLoraLabel()));
203+
const firstLoraWidget = this.widgets.findIndex(w => isLoraWidget(w));
204+
this.widgets.splice(firstLoraWidget, sortedWidgets.length, ...sortedWidgets);
205+
},
206+
};
207+
options.splice(options.length - 1, 0, fetchInfoMenuItem, fixPathsMenuItem, sortLoraWidgetsMenuItem);
193208
}
194209

195210
private updateCommonPrefix() {
@@ -834,6 +849,10 @@ class PowerLoraLoaderWidget extends RgthreeBaseWidget<PowerLoraLoaderWidgetValue
834849
ctx.restore();
835850
}
836851

852+
getLoraLabel() {
853+
return this.getLoraName();
854+
}
855+
837856
private getLoraName(commonPrefix = '', nameDisplay: NameDisplay = PROP_VALUE_NAME_OPTIONS_CIVITAI) {
838857
if (this.loraInfo?.name && nameDisplay === PROP_VALUE_NAME_OPTIONS_CIVITAI) {
839858
return this.loraInfo.name;

web/comfyui/power_lora_loader.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
106106
});
107107
},
108108
};
109-
options.splice(options.length - 1, 0, fetchInfoMenuItem, fixPathsMenuItem);
109+
const sortLoraWidgetsMenuItem = {
110+
content: "Sort LoRA widgets by name",
111+
callback: (_value, _options, _event, _parentMenu, _node) => {
112+
const loraWidgets = this.getLoraWidgets();
113+
const sortedWidgets = loraWidgets.toSorted((a, b) => a.getLoraLabel().localeCompare(b.getLoraLabel()));
114+
const firstLoraWidget = this.widgets.findIndex(w => isLoraWidget(w));
115+
this.widgets.splice(firstLoraWidget, sortedWidgets.length, ...sortedWidgets);
116+
},
117+
};
118+
options.splice(options.length - 1, 0, fetchInfoMenuItem, fixPathsMenuItem, sortLoraWidgetsMenuItem);
110119
}
111120
updateCommonPrefix() {
112121
if (!this.hasLoraWidgets) {
@@ -567,6 +576,9 @@ class PowerLoraLoaderWidget extends RgthreeBaseWidget {
567576
ctx.globalAlpha = app.canvas.editor_alpha;
568577
ctx.restore();
569578
}
579+
getLoraLabel() {
580+
return this.getLoraName();
581+
}
570582
getLoraName(commonPrefix = '', nameDisplay = PROP_VALUE_NAME_OPTIONS_CIVITAI) {
571583
var _c, _d;
572584
if (((_c = this.loraInfo) === null || _c === void 0 ? void 0 : _c.name) && nameDisplay === PROP_VALUE_NAME_OPTIONS_CIVITAI) {

0 commit comments

Comments
 (0)