mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 14:42:11 -03:00
refactor(AutoComplete): simplify search term extraction and insertion logic
This commit is contained in:
@@ -363,7 +363,7 @@ class BaseModelService(ABC):
|
|||||||
from ..config import config
|
from ..config import config
|
||||||
return config.get_preview_static_url(preview_url)
|
return config.get_preview_static_url(preview_url)
|
||||||
|
|
||||||
return None
|
return '/loras_static/images/no-preview.png'
|
||||||
|
|
||||||
async def get_model_civitai_url(self, model_name: str) -> Dict[str, Optional[str]]:
|
async def get_model_civitai_url(self, model_name: str) -> Dict[str, Optional[str]]:
|
||||||
"""Get the Civitai URL for a model file"""
|
"""Get the Civitai URL for a model file"""
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ class AutoComplete {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split on multiple delimiters: comma, space, '>' and other common separators
|
// Split on comma and '>' delimiters only (do not split on spaces)
|
||||||
const segments = beforeCursor.split(/[,\s>]+/);
|
const segments = beforeCursor.split(/[,\>]+/);
|
||||||
|
|
||||||
// Return the last non-empty segment as search term
|
// Return the last non-empty segment as search term
|
||||||
const lastSegment = segments[segments.length - 1] || '';
|
const lastSegment = segments[segments.length - 1] || '';
|
||||||
@@ -389,7 +389,6 @@ class AutoComplete {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.success && data.usage_tips) {
|
if (data.success && data.usage_tips) {
|
||||||
// Parse JSON string and extract strength
|
|
||||||
try {
|
try {
|
||||||
const usageTips = JSON.parse(data.usage_tips);
|
const usageTips = JSON.parse(data.usage_tips);
|
||||||
if (usageTips.strength && typeof usageTips.strength === 'number') {
|
if (usageTips.strength && typeof usageTips.strength === 'number') {
|
||||||
@@ -409,29 +408,15 @@ class AutoComplete {
|
|||||||
|
|
||||||
const currentValue = this.inputElement.value;
|
const currentValue = this.inputElement.value;
|
||||||
const caretPos = this.getCaretPosition();
|
const caretPos = this.getCaretPosition();
|
||||||
const lastCommaIndex = currentValue.lastIndexOf(',', caretPos - 1);
|
|
||||||
|
|
||||||
let newValue;
|
// Use getSearchTerm to get the current search term before cursor
|
||||||
let newCaretPos;
|
const beforeCursor = currentValue.substring(0, caretPos);
|
||||||
|
const searchTerm = this.getSearchTerm(beforeCursor);
|
||||||
|
const searchStartPos = caretPos - searchTerm.length;
|
||||||
|
|
||||||
if (lastCommaIndex === -1) {
|
// Only replace the search term, not everything after the last comma
|
||||||
// No comma found before cursor, replace from start or current search term start
|
const newValue = currentValue.substring(0, searchStartPos) + loraCode + currentValue.substring(caretPos);
|
||||||
const searchTerm = this.getSearchTerm(currentValue.substring(0, caretPos));
|
const newCaretPos = searchStartPos + loraCode.length;
|
||||||
const searchStartPos = caretPos - searchTerm.length;
|
|
||||||
newValue = currentValue.substring(0, searchStartPos) + loraCode + currentValue.substring(caretPos);
|
|
||||||
newCaretPos = searchStartPos + loraCode.length;
|
|
||||||
} else {
|
|
||||||
// Replace text after last comma before cursor
|
|
||||||
const afterCommaPos = lastCommaIndex + 1;
|
|
||||||
// Skip whitespace after comma
|
|
||||||
let insertPos = afterCommaPos;
|
|
||||||
while (insertPos < caretPos && /\s/.test(currentValue[insertPos])) {
|
|
||||||
insertPos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
newValue = currentValue.substring(0, insertPos) + loraCode + currentValue.substring(caretPos);
|
|
||||||
newCaretPos = insertPos + loraCode.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.inputElement.value = newValue;
|
this.inputElement.value = newValue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user