diff --git a/javascript/ext_umi.js b/javascript/ext_umi.js index 0fe7fad..d66f592 100644 --- a/javascript/ext_umi.js +++ b/javascript/ext_umi.js @@ -23,6 +23,11 @@ class UmiParser extends BaseTagParser { } }); + // Safety check since UMI parsing sometimes seems to trigger outside of an UMI subprompt and thus fails + if (umiTagsWithOperators.length === 0) { + return null; + } + const promptSplitToTags = umiTagsWithOperators.replace(']###[', '][').split("]["); const clean = (str) => str @@ -178,4 +183,23 @@ class UmiParser extends BaseTagParser { } } -PARSERS.push(new UmiParser(UMI_TRIGGER)); \ No newline at end of file +function updateUmiTags(tagType, newPrompt, textArea) { + // If it was a yaml wildcard, also update the umiPreviousTags + if (tagType === ResultType.yamlWildcard && originalTagword.length > 0) { + let umiSubPrompts = [...newPrompt.matchAll(UMI_PROMPT_REGEX)]; + + let umiTags = []; + umiSubPrompts.forEach(umiSubPrompt => { + umiTags = umiTags.concat([...umiSubPrompt[0].matchAll(UMI_TAG_REGEX)].map(x => x[1].toLowerCase())); + }); + + umiPreviousTags = umiTags; + + hideResults(textArea); + } +} + +// Add UMI parser +PARSERS.push(new UmiParser(UMI_TRIGGER)); +// Add tag update after insert +QUEUE_AFTER_INSERT.push(updateUmiTags); \ No newline at end of file diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 545aeb1..406ca7d 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -361,21 +361,7 @@ function insertTextAtCursor(textArea, result, tagword) { previousTags = tags; // Callback - processQueue(QUEUE_AFTER_INSERT, null, tagType); - - // If it was a yaml wildcard, also update the umiPreviousTags - if (tagType === ResultType.yamlWildcard && originalTagword.length > 0) { - let umiSubPrompts = [...newPrompt.matchAll(UMI_PROMPT_REGEX)]; - - let umiTags = []; - umiSubPrompts.forEach(umiSubPrompt => { - umiTags = umiTags.concat([...umiSubPrompt[0].matchAll(UMI_TAG_REGEX)].map(x => x[1].toLowerCase())); - }); - - umiPreviousTags = umiTags; - - hideResults(textArea); - } + processQueue(QUEUE_AFTER_INSERT, null, tagType, newPrompt, textArea); // Hide results after inserting if (tagType === ResultType.wildcardFile) { @@ -383,7 +369,7 @@ function insertTextAtCursor(textArea, result, tagword) { hideBlocked = true; autocomplete(textArea, prompt, sanitizedText); setTimeout(() => { hideBlocked = false; }, 100); - } else { + } else if (!hideBlocked && isVisible(textArea)) { hideResults(textArea); } }