mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-06-10 04:49:24 -03:00
fix(autocomplete): escape parentheses in prompt tag insertion (#951)
This commit is contained in:
@@ -183,6 +183,13 @@ function parseSearchTokens(term = '') {
|
||||
return { include, exclude };
|
||||
}
|
||||
|
||||
function escapePromptParentheses(text) {
|
||||
// In ComfyUI's CLIP text encoder, bare parentheses are weight adjustment syntax.
|
||||
// Tags containing literal parentheses must be escaped with backslash to prevent
|
||||
// them from being interpreted as weight modifiers. e.g. "foo (bar)" → "foo \(bar\)"
|
||||
return text.replace(/\(/g, '\\(').replace(/\)/g, '\\)');
|
||||
}
|
||||
|
||||
function formatAutocompleteInsertion(text = '') {
|
||||
const trimmed = typeof text === 'string' ? text.trim() : '';
|
||||
if (!trimmed) {
|
||||
@@ -253,7 +260,7 @@ function createDefaultBehavior(modelType) {
|
||||
if (!trimmed) {
|
||||
return '';
|
||||
}
|
||||
return formatAutocompleteInsertion(trimmed);
|
||||
return formatAutocompleteInsertion(escapePromptParentheses(trimmed));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -352,7 +359,7 @@ const MODEL_BEHAVIORS = {
|
||||
custom_words: {
|
||||
enablePreview: false,
|
||||
async getInsertText(_instance, relativePath) {
|
||||
return formatAutocompleteInsertion(relativePath);
|
||||
return formatAutocompleteInsertion(escapePromptParentheses(relativePath));
|
||||
},
|
||||
},
|
||||
prompt: {
|
||||
@@ -399,6 +406,8 @@ const MODEL_BEHAVIORS = {
|
||||
tagText = tagText.replace(/_/g, ' ');
|
||||
}
|
||||
|
||||
tagText = escapePromptParentheses(tagText);
|
||||
|
||||
return formatAutocompleteInsertion(tagText);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user