| 248 | var re_extranet_neg = /\(([^:^>]+:[\d.]+)\)/; |
| 249 | var re_extranet_g_neg = /\(([^:^>]+:[\d.]+)\)/g; |
| 250 | function tryToRemoveExtraNetworkFromPrompt(textarea, text, isNeg) { |
| 251 | var m = text.match(isNeg ? re_extranet_neg : re_extranet); |
| 252 | var replaced = false; |
| 253 | var newTextareaText; |
| 254 | if (m) { |
| 255 | var extraTextAfterNet = m[2]; |
| 256 | var partToSearch = m[1]; |
| 257 | var foundAtPosition = -1; |
| 258 | newTextareaText = textarea.value.replaceAll(isNeg ? re_extranet_g_neg : re_extranet_g, function(found, net, pos) { |
| 259 | m = found.match(isNeg ? re_extranet_neg : re_extranet); |
| 260 | if (m[1] == partToSearch) { |
| 261 | replaced = true; |
| 262 | foundAtPosition = pos; |
| 263 | return ""; |
| 264 | } |
| 265 | return found; |
| 266 | }); |
| 267 | if (foundAtPosition >= 0) { |
| 268 | if (extraTextAfterNet && newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) { |
| 269 | p0 = (newTextareaText[foundAtPosition - 1] == " ") ? foundAtPosition - 1 : foundAtPosition; |
| 270 | newTextareaText = newTextareaText.substr(0, p0) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length); |
| 271 | } |
| 272 | } |
| 273 | } else { |
| 274 | newTextareaText = textarea.value.replace(new RegExp(` ?${text}`, "g"), ""); |
| 275 | replaced = (newTextareaText != textarea.value); |
| 276 | } |
| 277 | |
| 278 | if (replaced) { |
| 279 | textarea.value = newTextareaText; |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | function updatePromptArea(text, textArea, isNeg) { |
| 288 | if (!tryToRemoveExtraNetworkFromPrompt(textArea, text, isNeg)) { |
| 289 | if (textArea.value !== "") { |
| 290 | textArea.value = textArea.value + " " + text; |