diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 3096011..7d94c4b 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -367,7 +367,6 @@ function updateSelectionStyle(textArea, newIndex, oldIndex) { var wildcardFiles = []; var wildcardExtFiles = []; -var wildcards = {}; var embeddings = []; var allTags = []; var results = []; @@ -408,12 +407,16 @@ function autocomplete(textArea, prompt, fixedTag = null) { tagword = tagword.toLowerCase(); - if (acConfig.useWildcards && [...tagword.matchAll(/\b__([^,_ ]+)__([^, ]*)\b/g)].length > 0) { + if (acConfig.useWildcards && [...tagword.matchAll(/\b__([^, ]+)__([^, ]*)\b/g)].length > 0) { // Show wildcards from a file with that name - wcMatch = [...tagword.matchAll(/\b__([^,_ ]+)__([^, ]*)\b/g)] + wcMatch = [...tagword.matchAll(/\b__([^, ]+)__([^, ]*)\b/g)] let wcFile = wcMatch[0][1]; let wcWord = wcMatch[0][2]; - results = wildcards[wcFile].filter(x => (wcWord !== null) ? x.toLowerCase().includes(wcWord) : x) // Filter by tagword + + let wildcards = readFile(`file/extensions/wildcards/wildcards/${wcFile}.txt`).split("\n") + .filter(x => x.trim().length > 0); // Remove empty lines + + results = wildcards.filter(x => (wcWord !== null && wcWord.length > 0) ? x.toLowerCase().includes(wcWord) : x) // Filter by tagword .map(x => [wcFile + ": " + x.trim(), "wildcardTag"]); // Mark as wildcard } else if (acConfig.useWildcards && (tagword.startsWith("__") && !tagword.endsWith("__") || tagword === "__")) { // Show available wildcard files @@ -607,23 +610,6 @@ onUiUpdate(function () { wildcardExtFiles = readFile("file/tags/temp/wce.txt").split("\n") .filter(x => x.trim().length > 0) // Remove empty lines .map(x => x.trim().replace(".txt", "")); // Remove file extension & newlines - - wildcardFiles.forEach(fName => { - try { - wildcards[fName] = readFile(`file/scripts/wildcards/${fName}.txt`).split("\n") - .filter(x => x.trim().length > 0); // Remove empty lines - } catch (e) { - console.log(`Could not load wildcards for ${fName}`); - } - }); - wildcardExtFiles.forEach(fName => { - try { - wildcards[fName] = readFile(`file/extensions/wildcards/wildcards/${fName}.txt`).split("\n") - .filter(x => x.trim().length > 0); // Remove empty lines - } catch (e) { - console.log(`Could not load wildcards for ${fName}`); - } - }); } catch (e) { console.error("Error loading wildcards: " + e); } diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 52c9485..80afe3c 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -15,13 +15,13 @@ TEMP_PATH = FILE_DIR.joinpath('tags/temp') def get_wildcards(): """Returns a list of all wildcards. Works on nested folders.""" wildcard_files = list(WILDCARD_PATH.rglob("*.txt")) - resolved = [str(w.relative_to(WILDCARD_PATH)) for w in wildcard_files if w.name != "put wildcards here.txt"] + resolved = [w.relative_to(WILDCARD_PATH).as_posix() for w in wildcard_files if w.name != "put wildcards here.txt"] return resolved def get_ext_wildcards(): """Returns a list of all extension wildcards. Works on nested folders.""" wildcard_files = list(WILDCARD_EXT_PATH.rglob("*.txt")) - resolved = [str(w.relative_to(WILDCARD_EXT_PATH)) for w in wildcard_files if w.name != "put wildcards here.txt"] + resolved = [w.relative_to(WILDCARD_EXT_PATH).as_posix() for w in wildcard_files if w.name != "put wildcards here.txt"] return resolved