diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 4a49f20..7cbfad4 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -422,7 +422,7 @@ function autocomplete(textArea, prompt, fixedTag = null) { wcPair = wildcardExtFiles.find(x => x[1].toLowerCase() === wcFile); let wildcards = readFile(`file/${wcPair[0]}/${wcPair[1]}.txt`).split("\n") - .filter(x => x.trim().length > 0); // Remove empty lines + .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 @@ -620,7 +620,7 @@ onUiUpdate(function () { wildcardFiles = wcFileArr.slice(1) .filter(x => x.trim().length > 0) // Remove empty lines .map(x => [wcBasePath, x.trim().replace(".txt", "")]); // Remove file extension & newlines - + // To support multiple sources, we need to separate them using the provided "-----" strings let wcExtFileArr = readFile(`file/${tagBasePath}/temp/wce.txt`).split("\n"); let splitIndices = []; @@ -640,7 +640,7 @@ onUiUpdate(function () { wcExtFile = wcExtFile.slice(1) .filter(x => x.trim().length > 0) // Remove empty lines .map(x => x.trim().replace(base, "").replace(".txt", "")); // Remove file extension & newlines; - + wcExtFile = wcExtFile.map(x => [base, x]); wildcardExtFiles.push(...wcExtFile); } diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 98d3697..a149421 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -11,6 +11,8 @@ FILE_DIR = Path().absolute() EXT_PATH = FILE_DIR.joinpath('extensions') # Tags base path + + def get_tags_base_path(): script_path = Path(scripts.basedir()) if (script_path.is_relative_to(EXT_PATH)): @@ -18,36 +20,43 @@ def get_tags_base_path(): else: return FILE_DIR.joinpath('tags') + TAGS_PATH = get_tags_base_path() # The path to the folder containing the wildcards and embeddings WILDCARD_PATH = FILE_DIR.joinpath('scripts/wildcards') EMB_PATH = FILE_DIR.joinpath('embeddings') + def find_ext_wildcard_paths(): """Returns the path to the extension wildcards folder""" found = list(EXT_PATH.rglob('**/wildcards/')) return found + # The path to the extension wildcards folder WILDCARD_EXT_PATHS = find_ext_wildcard_paths() # The path to the temporary files TEMP_PATH = TAGS_PATH.joinpath('temp') + def get_wildcards(): """Returns a list of all wildcards. Works on nested folders.""" wildcard_files = list(WILDCARD_PATH.rglob("*.txt")) - resolved = [w.relative_to(WILDCARD_PATH).as_posix() 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 = [] for path in WILDCARD_EXT_PATHS: wildcard_files.append(path.relative_to(FILE_DIR).as_posix()) - wildcard_files.extend(p.relative_to(path).as_posix() for p in path.rglob("*.txt") if p.name != "put wildcards here.txt") + wildcard_files.extend(p.relative_to(path).as_posix() for p in path.rglob( + "*.txt") if p.name != "put wildcards here.txt") wildcard_files.append("-----") return wildcard_files @@ -57,11 +66,13 @@ def get_embeddings(): """Returns a list of all embeddings""" return [str(e.relative_to(EMB_PATH)) for e in EMB_PATH.glob("**/*") if e.suffix in {".bin", ".pt", ".png"}] + def write_tag_base_path(): """Writes the tag base path to a fixed location temporary file""" with open(FILE_DIR.joinpath('tmp/tagAutocompletePath.txt'), 'w', encoding="utf-8") as f: f.write(TAGS_PATH.relative_to(FILE_DIR).as_posix()) + def write_to_temp_file(name, data): """Writes the given data to a temporary file""" with open(TEMP_PATH.joinpath(name), 'w', encoding="utf-8") as f: @@ -84,7 +95,8 @@ write_to_temp_file('emb.txt', []) # Write wildcards to wc.txt if found if WILDCARD_PATH.exists(): - wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards() + wildcards = [WILDCARD_PATH.relative_to( + FILE_DIR).as_posix()] + get_wildcards() if wildcards: write_to_temp_file('wc.txt', wildcards)