From b22435dd32b78a9b11384406aa948525ebb46b32 Mon Sep 17 00:00:00 2001 From: Dominik Reh Date: Sun, 29 Jan 2023 17:58:21 +0100 Subject: [PATCH] Extract wildcard keep open as well --- javascript/__globals.js | 1 + javascript/ext_umi.js | 5 ++++- javascript/ext_wildcards.js | 16 +++++++++++++++- javascript/tagAutocomplete.js | 18 +++++++----------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/javascript/__globals.js b/javascript/__globals.js index dacc065..7e62311 100644 --- a/javascript/__globals.js +++ b/javascript/__globals.js @@ -25,6 +25,7 @@ var resultCount = 0; var previousTags = []; var tagword = ""; var originalTagword = ""; +let hideBlocked = false; // Tag selection for keyboard navigation var selectedTag = null; diff --git a/javascript/ext_umi.js b/javascript/ext_umi.js index d66f592..5a4ed97 100644 --- a/javascript/ext_umi.js +++ b/javascript/ext_umi.js @@ -183,7 +183,7 @@ class UmiParser extends BaseTagParser { } } -function updateUmiTags(tagType, newPrompt, textArea) { +function updateUmiTags( tagType, sanitizedText, 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)]; @@ -196,7 +196,10 @@ function updateUmiTags(tagType, newPrompt, textArea) { umiPreviousTags = umiTags; hideResults(textArea); + + return true; } + return false; } // Add UMI parser diff --git a/javascript/ext_wildcards.js b/javascript/ext_wildcards.js index 18143ef..8a2f205 100644 --- a/javascript/ext_wildcards.js +++ b/javascript/ext_wildcards.js @@ -55,6 +55,20 @@ class WildcardFileParser extends BaseTagParser { } } +function keepOpenIfWildcard(tagType, sanitizedText, newPrompt, textArea) { + // If it's a wildcard, we want to keep the results open so the user can select another wildcard + if (tagType === ResultType.wildcardFile) { + hideBlocked = true; + autocomplete(textArea, newPrompt, sanitizedText); + setTimeout(() => { hideBlocked = false; }, 100); + return true; + } + return false; +} + // Register the parsers PARSERS.push(new WildcardParser(WC_TRIGGER)); -PARSERS.push(new WildcardFileParser(WC_FILE_TRIGGER)); \ No newline at end of file +PARSERS.push(new WildcardFileParser(WC_FILE_TRIGGER)); + +// Add the keep open function to the queue +QUEUE_AFTER_INSERT.push(keepOpenIfWildcard); \ No newline at end of file diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 406ca7d..24acbdb 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -288,10 +288,8 @@ function isEnabled() { const WEIGHT_REGEX = /[([]([^,()[\]:| ]+)(?::(?:\d+(?:\.\d+)?|\.\d+))?[)\]]/g; const TAG_REGEX = /(<[^\t\n\r,>]+>?|[^\s,|<>]+|<)/g -let hideBlocked = false; - // On click, insert the tag into the prompt textbox with respect to the cursor position -function insertTextAtCursor(textArea, result, tagword) { +async function insertTextAtCursor(textArea, result, tagword) { let text = result.text; let tagType = result.type; @@ -361,15 +359,13 @@ function insertTextAtCursor(textArea, result, tagword) { previousTags = tags; // Callback - processQueue(QUEUE_AFTER_INSERT, null, tagType, newPrompt, textArea); + let returns = await processQueueReturn(QUEUE_AFTER_INSERT, null, tagType, sanitizedText, newPrompt, textArea); + // Return if any queue function returned true (has handled hide/show already) + if (returns.some(x => x === true)) + return; - // Hide results after inserting - if (tagType === ResultType.wildcardFile) { - // If it's a wildcard, we want to keep the results open so the user can select another wildcard - hideBlocked = true; - autocomplete(textArea, prompt, sanitizedText); - setTimeout(() => { hideBlocked = false; }, 100); - } else if (!hideBlocked && isVisible(textArea)) { + // Hide results after inserting, if it hasn't been hidden already by a queue function + if (!hideBlocked && isVisible(textArea)) { hideResults(textArea); } }