Fix embeddings add/remove to/from prompt on click bugs.

This commit is contained in:
Sj-Si 2024-01-17 22:38:51 -05:00
parent ccee26b065
commit f25c81a744
2 changed files with 4 additions and 11 deletions

View File

@ -169,8 +169,8 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text, isNeg) {
var m = text.match(isNeg ? re_extranet_neg : re_extranet); var m = text.match(isNeg ? re_extranet_neg : re_extranet);
var replaced = false; var replaced = false;
var newTextareaText; var newTextareaText;
var extraTextBeforeNet = opts.extra_networks_add_text_separator;
if (m) { if (m) {
var extraTextBeforeNet = opts.extra_networks_add_text_separator;
var extraTextAfterNet = m[2]; var extraTextAfterNet = m[2];
var partToSearch = m[1]; var partToSearch = m[1];
var foundAtPosition = -1; var foundAtPosition = -1;
@ -183,7 +183,6 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text, isNeg) {
} }
return found; return found;
}); });
if (foundAtPosition >= 0) { if (foundAtPosition >= 0) {
if (extraTextAfterNet && newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) { if (extraTextAfterNet && newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) {
newTextareaText = newTextareaText.substr(0, foundAtPosition) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length); newTextareaText = newTextareaText.substr(0, foundAtPosition) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length);
@ -193,13 +192,8 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text, isNeg) {
} }
} }
} else { } else {
newTextareaText = textarea.value.replaceAll(new RegExp(text, "g"), function(found) { newTextareaText = textarea.value.replaceAll(new RegExp(`((?:${extraTextBeforeNet})?${text})`, "g"), "");
if (found == text) { replaced = (newTextareaText != textarea.value);
replaced = true;
return "";
}
return found;
});
} }
if (replaced) { if (replaced) {
@ -211,7 +205,6 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text, isNeg) {
} }
function updatePromptArea(text, textArea, isNeg) { function updatePromptArea(text, textArea, isNeg) {
if (!tryToRemoveExtraNetworkFromPrompt(textArea, text, isNeg)) { if (!tryToRemoveExtraNetworkFromPrompt(textArea, text, isNeg)) {
textArea.value = textArea.value + opts.extra_networks_add_text_separator + text; textArea.value = textArea.value + opts.extra_networks_add_text_separator + text;
} }

View File

@ -236,7 +236,7 @@ class ExtraNetworksPage:
**{ **{
"tabname": tabname, "tabname": tabname,
"prompt": item["prompt"], "prompt": item["prompt"],
"neg_prompt": item.get("negative_prompt", ""), "neg_prompt": item.get("negative_prompt", "''"),
"allow_neg": str(self.allow_negative_prompt).lower(), "allow_neg": str(self.allow_negative_prompt).lower(),
} }
) )