Skip to content

Commit

Permalink
Use correct separator for extra networks
Browse files Browse the repository at this point in the history
Now uses the dedicated webui option for it instead of comma
Closes #160
  • Loading branch information
DominikDoom committed Apr 13, 2023
1 parent 223abf5 commit 5fbc18e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions javascript/tagAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async function syncOptions() {
},
// Settings not from tac but still used by the script
extraNetworksDefaultMultiplier: opts["extra_networks_default_multiplier"],
extraNetworksSeparator: opts["extra_networks_add_text_separator"],
// Custom mapping settings
keymap: JSON.parse(opts["tac_keymap"]),
colorMap: JSON.parse(opts["tac_colormap"])
Expand Down Expand Up @@ -311,18 +312,23 @@ async function insertTextAtCursor(textArea, result, tagword) {
let match = surrounding.match(new RegExp(escapeRegExp(`${tagword}`), "i"));
let afterInsertCursorPos = editStart + match.index + sanitizedText.length;

var optionalComma = "";
if (CFG.appendComma && ![ResultType.wildcardFile, ResultType.yamlWildcard].includes(tagType)) {
optionalComma = surrounding.match(new RegExp(`${escapeRegExp(tagword)}[,:]`, "i")) !== null ? "" : ", ";
var optionalSeparator = "";
let extraNetworkTypes = [ResultType.hypernetwork, ResultType.lora];
let noCommaTypes = [ResultType.wildcardFile, ResultType.yamlWildcard].concat(extraNetworkTypes);
if (CFG.appendComma && !noCommaTypes.includes(tagType)) {
optionalSeparator = surrounding.match(new RegExp(`${escapeRegExp(tagword)}[,:]`, "i")) !== null ? "" : ", ";
} else if (extraNetworkTypes.includes(tagType)) {
// Use the dedicated separator for extra networks if it's defined, otherwise fall back to space
optionalSeparator = CFG.extraNetworksSeparator || " ";
}

// Replace partial tag word with new text, add comma if needed
let insert = surrounding.replace(match, sanitizedText + optionalComma);
let insert = surrounding.replace(match, sanitizedText + optionalSeparator);

// Add back start
var newPrompt = prompt.substring(0, editStart) + insert + prompt.substring(editEnd);
textArea.value = newPrompt;
textArea.selectionStart = afterInsertCursorPos + optionalComma.length;
textArea.selectionStart = afterInsertCursorPos + optionalSeparator.length;
textArea.selectionEnd = textArea.selectionStart

// Since we've modified a Gradio Textbox component manually, we need to simulate an `input` DOM event to ensure it's propagated back to python.
Expand Down

0 comments on commit 5fbc18e

Please sign in to comment.