From 14a4440c33b10790ce7fc27ca091fe2d0cae6350 Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Mon, 7 Aug 2023 17:38:40 +0200 Subject: [PATCH] Fix extra network sorting Caused by loras including their (hidden) folder prefixes instead of just by name --- javascript/ext_loras.js | 16 ++++++++-------- javascript/ext_lycos.js | 16 ++++++++-------- javascript/tagAutocomplete.js | 14 ++++++-------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/javascript/ext_loras.js b/javascript/ext_loras.js index 2e99eef..44ad8f0 100644 --- a/javascript/ext_loras.js +++ b/javascript/ext_loras.js @@ -16,7 +16,12 @@ class LoraParser extends BaseTagParser { // Add final results let finalResults = []; tempResults.forEach(t => { - let result = new AutocompleteResult(t[0].trim(), ResultType.lora) + const text = t[0].trim(); + let lastDot = text.lastIndexOf(".") > -1 ? text.lastIndexOf(".") : text.length; + let lastSlash = text.lastIndexOf("/") > -1 ? text.lastIndexOf("/") : 0; + let name = text.substring(lastSlash + 1, lastDot); + + let result = new AutocompleteResult(name, ResultType.lora) result.meta = "Lora"; result.hash = t[1]; finalResults.push(result); @@ -41,17 +46,12 @@ async function load() { async function sanitize(tagType, text) { if (tagType === ResultType.lora) { let multiplier = TAC_CFG.extraNetworksDefaultMultiplier; - let finalComponent = text.lastIndexOf("/") > -1 ? text.substring(text.lastIndexOf("/") + 1) : text; - let info = await fetchAPI(`tacapi/v1/lora-info/${finalComponent}`) + let info = await fetchAPI(`tacapi/v1/lora-info/${text}`) if (info && info["preferred weight"]) { multiplier = info["preferred weight"]; } - const lastDot = text.lastIndexOf("."); - const lastSlash = text.lastIndexOf("/"); - const name = text.substring(lastSlash + 1, lastDot); - - return ``; + return ``; } return null; } diff --git a/javascript/ext_lycos.js b/javascript/ext_lycos.js index a7f9cf8..9fd8ac1 100644 --- a/javascript/ext_lycos.js +++ b/javascript/ext_lycos.js @@ -16,7 +16,12 @@ class LycoParser extends BaseTagParser { // Add final results let finalResults = []; tempResults.forEach(t => { - let result = new AutocompleteResult(t[0].trim(), ResultType.lyco) + const text = t[0].trim(); + let lastDot = text.lastIndexOf(".") > -1 ? text.lastIndexOf(".") : text.length; + let lastSlash = text.lastIndexOf("/") > -1 ? text.lastIndexOf("/") : 0; + let name = text.substring(lastSlash + 1, lastDot); + + let result = new AutocompleteResult(name, ResultType.lyco) result.meta = "Lyco"; result.hash = t[1]; finalResults.push(result); @@ -41,17 +46,12 @@ async function load() { async function sanitize(tagType, text) { if (tagType === ResultType.lyco) { let multiplier = TAC_CFG.extraNetworksDefaultMultiplier; - let finalComponent = text.lastIndexOf("/") > -1 ? text.substring(text.lastIndexOf("/") + 1) : text; - let info = await fetchAPI(`tacapi/v1/lyco-info/${finalComponent}`) + let info = await fetchAPI(`tacapi/v1/lyco-info/${text}`) if (info && info["preferred weight"]) { multiplier = info["preferred weight"]; } - const lastDot = text.lastIndexOf("."); - const lastSlash = text.lastIndexOf("/"); - const name = text.substring(lastSlash + 1, lastDot); - - return ``; + return ``; } return null; } diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 071a986..62a1c85 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -453,8 +453,7 @@ async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithout let keywords = null; // Check built-in activation words first if (tagType === ResultType.lora || tagType === ResultType.lyco) { - let finalComponent = result.text.lastIndexOf("/") > -1 ? result.text.substring(result.text.lastIndexOf("/") + 1) : result.text; - let info = await fetchAPI(`tacapi/v1/lora-info/${finalComponent}`) + let info = await fetchAPI(`tacapi/v1/lora-info/${result.text}`) if (info && info["activation text"]) { keywords = info["activation text"]; } @@ -585,11 +584,6 @@ function addResultsToList(textArea, results, tagword, resetList) { if (!TAC_CFG.alias.onlyShowAlias && result.text !== bestAlias) displayText += " ➝ " + result.text; - } else if (result.type === ResultType.lora || result.type === ResultType.lyco) { - let lastDot = result.text.lastIndexOf("."); - let lastSlash = result.text.lastIndexOf("/"); - let name = result.text.substring(lastSlash + 1, lastDot); - displayText = escapeHTML(name); } else { // No alias displayText = escapeHTML(result.text); } @@ -713,7 +707,11 @@ function updateSelectionStyle(textArea, newIndex, oldIndex) { // make it safer if (newIndex !== null) { - items[newIndex].classList.add('selected'); + let selected = items[newIndex]; + selected.classList.add('selected'); + + // Set scrolltop to selected item + resultDiv.scrollTop = selected.offsetTop - resultDiv.offsetTop; } // Set scrolltop to selected item if we are showing more than max results