Skip to content

Commit

Permalink
account for customizable extra network separators in remove code
Browse files Browse the repository at this point in the history
previous behavior only searched for leading spaces
  • Loading branch information
zixaphir committed Aug 31, 2023
1 parent 6adf2b7 commit 41196cc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions javascript/extraNetworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,22 @@ function setupExtraNetworks() {
onUiLoaded(setupExtraNetworks);

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

function tryToRemoveExtraNetworkFromPrompt(textarea, text) {
function reEscape(s) {
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
var m = text.match(re_extranet);
var replaced = false;
var newTextareaText;
if (m) {
var extraTextAfterNet = m[2];
var partToSearch = m[1];
var foundAtPosition = -1;
newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found, net, pos) {
var escapedSeparator = reEscape(opts.extra_networks_add_text_separator);
var re = new RegExp(escapedSeparator + re_extranet_str, 'g');
newTextareaText = textarea.value.replaceAll(re, function(found, net, pos) {
m = found.match(re_extranet);
if (m[1] == partToSearch) {
replaced = true;
Expand Down

0 comments on commit 41196cc

Please sign in to comment.