Skip to content

Commit

Permalink
Merge pull request #12877 from zixaphir/removeExtraNetworksFromPrompt…
Browse files Browse the repository at this point in the history
…_fix

account for customizable extra network separators in remove code
  • Loading branch information
AUTOMATIC1111 authored Sep 30, 2023
2 parents a0e979b + 26d0d87 commit fcfe5c1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions javascript/extraNetworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,15 @@ function setupExtraNetworks() {

onUiLoaded(setupExtraNetworks);

var re_extranet = /<([^:]+:[^:]+):[\d.]+>(.*)/;
var re_extranet_g = /\s+<([^:]+:[^:]+):[\d.]+>/g;
var re_extranet = /<([^:^>]+:[^:]+):[\d.]+>(.*)/;
var re_extranet_g = /<([^:^>]+:[^:]+):[\d.]+>/g;

function tryToRemoveExtraNetworkFromPrompt(textarea, text) {
var m = text.match(re_extranet);
var replaced = false;
var newTextareaText;
if (m) {
var extraTextBeforeNet = opts.extra_networks_add_text_separator;
var extraTextAfterNet = m[2];
var partToSearch = m[1];
var foundAtPosition = -1;
Expand All @@ -161,8 +162,13 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text) {
return found;
});

if (foundAtPosition >= 0 && newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) {
newTextareaText = newTextareaText.substr(0, foundAtPosition) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length);
if (foundAtPosition >= 0) {
if (newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) {
newTextareaText = newTextareaText.substr(0, foundAtPosition) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length);
}
if (newTextareaText.substr(foundAtPosition - extraTextBeforeNet.length, extraTextBeforeNet.length) == extraTextBeforeNet) {
newTextareaText = newTextareaText.substr(0, foundAtPosition - extraTextBeforeNet.length) + newTextareaText.substr(foundAtPosition);
}
}
} else {
newTextareaText = textarea.value.replaceAll(new RegExp(text, "g"), function(found) {
Expand Down

0 comments on commit fcfe5c1

Please sign in to comment.