From 707202ed71985c9c8f3752623960b66de10dc0b6 Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Thu, 6 Jul 2023 12:52:10 +0200 Subject: [PATCH] Add override option for space at end of prompt Closes #196 --- javascript/tagAutocomplete.js | 7 ++++++- scripts/tag_autocomplete_helper.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index a70d00d..1094a0e 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -200,6 +200,7 @@ async function syncOptions() { escapeParentheses: opts["tac_escapeParentheses"], appendComma: opts["tac_appendComma"], appendSpace: opts["tac_appendSpace"], + alwaysSpaceAtEnd: opts["tac_alwaysSpaceAtEnd"], wildcardCompletionMode: opts["tac_wildcardCompletionMode"], // Alias settings alias: { @@ -420,11 +421,15 @@ async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithout let extraNetworkTypes = [ResultType.hypernetwork, ResultType.lora]; let noCommaTypes = [ResultType.wildcardFile, ResultType.yamlWildcard].concat(extraNetworkTypes); if (!noCommaTypes.includes(tagType)) { + // Append comma if enabled and not already present if (TAC_CFG.appendComma) optionalSeparator = surrounding.match(new RegExp(`${escapeRegExp(tagword)}[,:]`, "i")) !== null ? "" : ","; - + // Add space if enabled if (TAC_CFG.appendSpace) optionalSeparator += " "; + // If at end of prompt and enabled, override the normal setting if not already added + if (!TAC_CFG.appendSpace && TAC_CFG.alwaysSpaceAtEnd) + optionalSeparator += surrounding.match(new RegExp(`${escapeRegExp(tagword)}$`, "im")) !== null ? " " : ""; } else if (extraNetworkTypes.includes(tagType)) { // Use the dedicated separator for extra networks if it's defined, otherwise fall back to space optionalSeparator = TAC_CFG.extraNetworksSeparator || " "; diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 38ca9d2..a0c1c99 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -321,6 +321,7 @@ def on_ui_settings(): "tac_escapeParentheses": shared.OptionInfo(True, "Escape parentheses on insertion"), "tac_appendComma": shared.OptionInfo(True, "Append comma on tag autocompletion"), "tac_appendSpace": shared.OptionInfo(True, "Append space on tag autocompletion").info("will append after comma if the above is enabled"), + "tac_alwaysSpaceAtEnd": shared.OptionInfo(True, "Always append space if inserting at the end of the textbox").info("takes precedence over the regular space setting for that position"), "tac_wildcardCompletionMode": shared.OptionInfo("To next folder level", "How to complete nested wildcard paths", gr.Dropdown, lambda: {"choices": ["To next folder level","To first difference","Always fully"]}).info("e.g. \"hair/colours/light/...\""), # Alias settings "tac_alias.searchByAlias": shared.OptionInfo(True, "Search by alias"),