mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 14:42:11 -03:00
feat: implement drag-and-drop reordering for LoRA entries and enhance keyboard navigation. Fixes #302
This commit is contained in:
@@ -183,4 +183,47 @@ export function updateConnectedTriggerWords(node, loraNames) {
|
||||
})
|
||||
}).catch(err => console.error("Error fetching trigger words:", err));
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeLoras(lorasText, lorasArr) {
|
||||
// Parse lorasText into a map: name -> {strength, clipStrength}
|
||||
const parsedLoras = {};
|
||||
let match;
|
||||
LORA_PATTERN.lastIndex = 0;
|
||||
while ((match = LORA_PATTERN.exec(lorasText)) !== null) {
|
||||
const name = match[1];
|
||||
const modelStrength = Number(match[2]);
|
||||
const clipStrength = match[3] ? Number(match[3]) : modelStrength;
|
||||
parsedLoras[name] = { strength: modelStrength, clipStrength };
|
||||
}
|
||||
|
||||
// Build result array in the order of lorasArr
|
||||
const result = [];
|
||||
const usedNames = new Set();
|
||||
|
||||
for (const lora of lorasArr) {
|
||||
if (parsedLoras[lora.name]) {
|
||||
result.push({
|
||||
name: lora.name,
|
||||
strength: lora.strength !== undefined ? lora.strength : parsedLoras[lora.name].strength,
|
||||
active: lora.active !== undefined ? lora.active : true,
|
||||
clipStrength: lora.clipStrength !== undefined ? lora.clipStrength : parsedLoras[lora.name].clipStrength,
|
||||
});
|
||||
usedNames.add(lora.name);
|
||||
}
|
||||
}
|
||||
|
||||
// Add any new loras from lorasText that are not in lorasArr, in their text order
|
||||
for (const name in parsedLoras) {
|
||||
if (!usedNames.has(name)) {
|
||||
result.push({
|
||||
name,
|
||||
strength: parsedLoras[name].strength,
|
||||
active: true,
|
||||
clipStrength: parsedLoras[name].clipStrength,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user