Skip to content

Commit

Permalink
Add option to include embeddings in normal search
Browse files Browse the repository at this point in the history
along with new keybind functionality for quick jumping between sections.
Closes #230
  • Loading branch information
DominikDoom committed Sep 7, 2023
1 parent e23bb6d commit 57821aa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions javascript/__globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
2 changes: 1 addition & 1 deletion javascript/ext_embeddings.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
31 changes: 27 additions & 4 deletions javascript/tagAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -985,6 +986,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) {
}

results = [];
resultCountBeforeNormalTags = 0;
tagword = tagword.toLowerCase().replace(/[\n\r]/g, "");

// Process all parsers
Expand Down Expand Up @@ -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("*")) {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions scripts/tag_autocomplete_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def needs_restart(self):
"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"),
Expand Down

0 comments on commit 57821aa

Please sign in to comment.