diff --git a/javascript/__globals.js b/javascript/__globals.js index 35b9dcf..f705f35 100644 --- a/javascript/__globals.js +++ b/javascript/__globals.js @@ -36,6 +36,7 @@ let hideBlocked = false; // Tag selection for keyboard navigation var selectedTag = null; var oldSelectedTag = null; +var resultCountBeforeNormalTags = 0; // Lora keyword undo/redo history var textBeforeKeywordInsertion = ""; diff --git a/javascript/ext_embeddings.js b/javascript/ext_embeddings.js index 30ce48f..e51aa4b 100644 --- a/javascript/ext_embeddings.js +++ b/javascript/ext_embeddings.js @@ -1,5 +1,5 @@ const EMB_REGEX = /<(?!l:|h:|c:)[^,> ]*>?/g; -const EMB_TRIGGER = () => TAC_CFG.useEmbeddings && tagword.match(EMB_REGEX); +const EMB_TRIGGER = () => TAC_CFG.useEmbeddings && (tagword.match(EMB_REGEX) || TAC_CFG.includeEmbeddingsInNormalResults); class EmbeddingParser extends BaseTagParser { parse() { diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 073240d..15a6904 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -211,6 +211,7 @@ async function syncOptions() { useWildcards: opts["tac_useWildcards"], sortWildcardResults: opts["tac_sortWildcardResults"], useEmbeddings: opts["tac_useEmbeddings"], + includeEmbeddingsInNormalResults: opts["tac_includeEmbeddingsInNormalResults"], useHypernetworks: opts["tac_useHypernetworks"], useLoras: opts["tac_useLoras"], useLycos: opts["tac_useLycos"], @@ -985,6 +986,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) { } results = []; + resultCountBeforeNormalTags = 0; tagword = tagword.toLowerCase().replace(/[\n\r]/g, ""); // Process all parsers @@ -1024,7 +1026,13 @@ async function autocomplete(textArea, prompt, fixedTag = null) { }); } } - } else { // Else search the normal tag list + } + // Else search the normal tag list + if (!resultCandidates || resultCandidates.length === 0 + || (TAC_CFG.includeEmbeddingsInNormalResults && !(tagword.startsWith("<") || tagword.startsWith("*<"))) + ) { + resultCountBeforeNormalTags = results.length; + // Create escaped search regex with support for * as a start placeholder let searchRegex; if (tagword.startsWith("*")) { @@ -1080,7 +1088,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) { // Slice if the user has set a max result count if (!TAC_CFG.showAllResults) { - results = results.slice(0, TAC_CFG.maxResults); + results = results.slice(0, TAC_CFG.maxResults + resultCountBeforeNormalTags); } } @@ -1148,10 +1156,25 @@ function navigateInList(textArea, event) { } break; case keys["JumpToStart"]: - selectedTag = 0; + if (TAC_CFG.includeEmbeddingsInNormalResults && + selectedTag > resultCountBeforeNormalTags && + resultCountBeforeNormalTags > 0 + ) { + selectedTag = resultCountBeforeNormalTags; + } else { + selectedTag = 0; + } break; case keys["JumpToEnd"]: - selectedTag = resultCount - 1; + // Jump to the end of the list, or the end of embeddings if they are included in the normal results + if (TAC_CFG.includeEmbeddingsInNormalResults && + selectedTag < resultCountBeforeNormalTags && + resultCountBeforeNormalTags > 0 + ) { + selectedTag = Math.min(resultCountBeforeNormalTags, resultCount - 1); + } else { + selectedTag = resultCount - 1; + } break; case keys["ChooseSelected"]: if (selectedTag !== null) { diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index b735701..c90f35d 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -369,6 +369,7 @@ def on_ui_settings(): "tac_useWildcards": shared.OptionInfo(True, "Search for wildcards"), "tac_sortWildcardResults": shared.OptionInfo(True, "Sort wildcard file contents alphabetically").info("If your wildcard files have a specific custom order, disable this to keep it"), "tac_useEmbeddings": shared.OptionInfo(True, "Search for embeddings"), + "tac_includeEmbeddingsInNormalResults": shared.OptionInfo(False, "Include embeddings in normal tag results").info("The 'JumpTo...' keybinds (End & Home key by default) will select the first non-embedding result of their direction on the first press for quick navigation in longer lists."), "tac_useHypernetworks": shared.OptionInfo(True, "Search for hypernetworks"), "tac_useLoras": shared.OptionInfo(True, "Search for Loras"), "tac_useLycos": shared.OptionInfo(True, "Search for LyCORIS/LoHa"),