Merge branch 'main' into feature-sort-by-frequent-use

This commit is contained in:
DominikDoom
2024-03-03 13:52:32 +01:00
9 changed files with 56 additions and 23 deletions

View File

@@ -309,7 +309,11 @@ function toNgrams(inputArray, size) {
);
}
function escapeRegExp(string) {
function escapeRegExp(string, wildcardMatching = false) {
if (wildcardMatching) {
// Escape all characters except asterisks and ?, which should be treated separately as placeholders.
return string.replace(/[-[\]{}()+.,\\^$|#\s]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.');
}
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
function escapeHTML(unsafeText) {

View File

@@ -7,7 +7,10 @@ class ChantParser extends BaseTagParser {
let tempResults = [];
if (tagword !== "<" && tagword !== "<c:") {
let searchTerm = tagword.replace("<chant:", "").replace("<c:", "").replace("<", "");
let filterCondition = x => x.terms.toLowerCase().includes(searchTerm) || x.name.toLowerCase().includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x.terms.toLowerCase()) || regex.test(x.name.toLowerCase());
};
tempResults = chants.filter(x => filterCondition(x)); // Filter by tagword
} else {
tempResults = chants;
@@ -51,4 +54,4 @@ PARSERS.push(new ChantParser(CHANT_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_AFTER_CONFIG_CHANGE.push(load);
QUEUE_AFTER_CONFIG_CHANGE.push(load);

View File

@@ -16,7 +16,10 @@ class EmbeddingParser extends BaseTagParser {
searchTerm = searchTerm.slice(3);
}
let filterCondition = x => x[0].toLowerCase().includes(searchTerm) || x[0].toLowerCase().replaceAll(" ", "_").includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x[0].toLowerCase()) || regex.test(x[0].toLowerCase().replaceAll(" ", "_"));
};
if (versionString)
tempResults = embeddings.filter(x => filterCondition(x) && x[2] && x[2].toLowerCase() === versionString.toLowerCase()); // Filter by tagword
@@ -29,7 +32,11 @@ class EmbeddingParser extends BaseTagParser {
// Add final results
let finalResults = [];
tempResults.forEach(t => {
let result = new AutocompleteResult(t[0].trim(), ResultType.embedding)
let lastDot = t[0].lastIndexOf(".") > -1 ? t[0].lastIndexOf(".") : t[0].length;
let lastSlash = t[0].lastIndexOf("/") > -1 ? t[0].lastIndexOf("/") : -1;
let name = t[0].trim().substring(lastSlash + 1, lastDot);
let result = new AutocompleteResult(name, ResultType.embedding)
result.sortKey = t[1];
result.meta = t[2] + " Embedding";
finalResults.push(result);
@@ -62,4 +69,4 @@ PARSERS.push(new EmbeddingParser(EMB_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_SANITIZE.push(sanitize);

View File

@@ -7,7 +7,10 @@ class HypernetParser extends BaseTagParser {
let tempResults = [];
if (tagword !== "<" && tagword !== "<h:" && tagword !== "<hypernet:") {
let searchTerm = tagword.replace("<hypernet:", "").replace("<h:", "").replace("<", "");
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_"));
};
tempResults = hypernetworks.filter(x => filterCondition(x[0])); // Filter by tagword
} else {
tempResults = hypernetworks;
@@ -49,4 +52,4 @@ PARSERS.push(new HypernetParser(HYP_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_SANITIZE.push(sanitize);

View File

@@ -7,7 +7,10 @@ class LoraParser extends BaseTagParser {
let tempResults = [];
if (tagword !== "<" && tagword !== "<l:" && tagword !== "<lora:") {
let searchTerm = tagword.replace("<lora:", "").replace("<l:", "").replace("<", "");
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_"));
};
tempResults = loras.filter(x => filterCondition(x[0])); // Filter by tagword
} else {
tempResults = loras;
@@ -61,4 +64,4 @@ PARSERS.push(new LoraParser(LORA_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_SANITIZE.push(sanitize);

View File

@@ -7,7 +7,10 @@ class LycoParser extends BaseTagParser {
let tempResults = [];
if (tagword !== "<" && tagword !== "<l:" && tagword !== "<lyco:" && tagword !== "<lora:") {
let searchTerm = tagword.replace("<lyco:", "").replace("<lora:", "").replace("<l:", "").replace("<", "");
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_"));
};
tempResults = lycos.filter(x => filterCondition(x[0])); // Filter by tagword
} else {
tempResults = lycos;
@@ -62,4 +65,4 @@ PARSERS.push(new LycoParser(LYCO_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_SANITIZE.push(sanitize);

View File

@@ -18,7 +18,10 @@ class StyleParser extends BaseTagParser {
if (tagword !== matchGroups[1]) {
let searchTerm = tagword.replace(matchGroups[1], "");
let filterCondition = x => x[0].toLowerCase().includes(searchTerm) || x[0].toLowerCase().replaceAll(" ", "_").includes(searchTerm);
let filterCondition = x => {
let regex = new RegExp(escapeRegExp(searchTerm, true), 'i');
return regex.test(x[0].toLowerCase()) || regex.test(x[0].toLowerCase().replaceAll(" ", "_"));
};
tempResults = styleNames.filter(x => filterCondition(x)); // Filter by tagword
} else {
tempResults = styleNames;
@@ -64,4 +67,4 @@ PARSERS.push(new StyleParser(STYLE_TRIGGER));
// Add our utility functions to their respective queues
QUEUE_FILE_LOAD.push(load);
QUEUE_SANITIZE.push(sanitize);
QUEUE_SANITIZE.push(sanitize);

View File

@@ -220,7 +220,7 @@ async function syncOptions() {
includeEmbeddingsInNormalResults: opts["tac_includeEmbeddingsInNormalResults"],
useHypernetworks: opts["tac_useHypernetworks"],
useLoras: opts["tac_useLoras"],
useLycos: opts["tac_useLycos"],
useLycos: opts["tac_useLycos"],
useLoraPrefixForLycos: opts["tac_useLoraPrefixForLycos"],
showWikiLinks: opts["tac_showWikiLinks"],
showExtraNetworkPreviews: opts["tac_showExtraNetworkPreviews"],
@@ -1241,12 +1241,17 @@ function navigateInList(textArea, event) {
if (!validKeys.includes(event.key)) return;
if (!isVisible(textArea)) return
// Return if ctrl key is pressed to not interfere with weight editing shortcut
if (event.ctrlKey || event.altKey || event.shiftKey || event.metaKey) return;
// Add modifier keys to base as text+.
let modKey = "";
if (event.ctrlKey) modKey += "Ctrl+";
if (event.altKey) modKey += "Alt+";
if (event.shiftKey) modKey += "Shift+";
if (event.metaKey) modKey += "Meta+";
modKey += event.key;
oldSelectedTag = selectedTag;
switch (event.key) {
switch (modKey) {
case keys["MoveUp"]:
if (selectedTag === null) {
selectedTag = resultCount - 1;
@@ -1317,6 +1322,8 @@ function navigateInList(textArea, event) {
case keys["Close"]:
hideResults(textArea);
break;
default:
if (event.ctrlKey || event.altKey || event.shiftKey || event.metaKey) return;
}
let moveKeys = [keys["MoveUp"], keys["MoveDown"], keys["JumpUp"], keys["JumpDown"], keys["JumpToStart"], keys["JumpToEnd"]];
if (selectedTag === resultCount - 1 && moveKeys.includes(event.key)) {