From 018c6c8198720b9d6fc915dc226763634b0590fb Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Wed, 13 Sep 2023 21:50:41 +0200 Subject: [PATCH 1/2] Fix Umi tag gathering & sorting Fixes #238 --- javascript/ext_umi.js | 5 +++++ javascript/tagAutocomplete.js | 2 +- scripts/tag_autocomplete_helper.py | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/javascript/ext_umi.js b/javascript/ext_umi.js index c076734..a55f80c 100644 --- a/javascript/ext_umi.js +++ b/javascript/ext_umi.js @@ -149,6 +149,7 @@ class UmiParser extends BaseTagParser { finalResults.push(result); }); + finalResults = finalResults.sort((a, b) => b.count - a.count); return finalResults; } else if (showAll) { let filteredWildcardsSorted = filteredWildcards(""); @@ -163,6 +164,8 @@ class UmiParser extends BaseTagParser { originalTagword = tagword; tagword = ""; + + finalResults = finalResults.sort((a, b) => b.count - a.count); return finalResults; } } else { @@ -178,6 +181,8 @@ class UmiParser extends BaseTagParser { originalTagword = tagword; tagword = ""; + + finalResults = finalResults.sort((a, b) => b.count - a.count); return finalResults; } } diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 775ba39..2146156 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -1002,7 +1002,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) { tagword = tagword.toLowerCase().replace(/[\n\r]/g, ""); // Process all parsers - let resultCandidates = await processParsers(textArea, prompt); + let resultCandidates = (await processParsers(textArea, prompt)).filter(x => x.length > 0); // If one ore more result candidates match, use their results if (resultCandidates && resultCandidates.length > 0) { // Flatten our candidate(s) diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 1a05f01..f95aa85 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -52,7 +52,9 @@ def is_umi_format(data): break return not issue_found -def parse_umi_format(umi_tags, count, data): +count = 0 +def parse_umi_format(umi_tags, data): + global count for item in data: umi_tags[count] = ','.join(data[item]['Tags']) count += 1 @@ -82,7 +84,6 @@ def get_yaml_wildcards(): yaml_wildcards = {} umi_tags = {} # { tag: count } - count = 0 for path in yaml_files: try: @@ -90,7 +91,7 @@ def get_yaml_wildcards(): data = yaml.safe_load(file) if (data): if (is_umi_format(data)): - parse_umi_format(umi_tags, count, data) + parse_umi_format(umi_tags, data) else: parse_dynamic_prompt_format(yaml_wildcards, data, path) else: From 5067afeee95b9a742742333c67837cd35d5d732a Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Wed, 13 Sep 2023 21:55:09 +0200 Subject: [PATCH 2/2] Add missing null safety --- javascript/tagAutocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 2146156..3f69cc0 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -1002,7 +1002,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) { tagword = tagword.toLowerCase().replace(/[\n\r]/g, ""); // Process all parsers - let resultCandidates = (await processParsers(textArea, prompt)).filter(x => x.length > 0); + let resultCandidates = (await processParsers(textArea, prompt))?.filter(x => x.length > 0); // If one ore more result candidates match, use their results if (resultCandidates && resultCandidates.length > 0) { // Flatten our candidate(s)