Extract UMI after insert update

This commit is contained in:
Dominik Reh
2023-01-29 17:36:02 +01:00
parent fad8b3dc88
commit b0347d1ca7
2 changed files with 27 additions and 17 deletions

View File

@@ -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));
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);

View File

@@ -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);
}
}