mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
feat: enhance search with include/exclude tokens and improved sorting
- Add token parsing to support include/exclude search terms using "-" prefix - Implement token-based matching logic for relative path searches - Improve search result sorting by prioritizing prefix matches and match position - Add frontend test for multi-token highlighting with exclusion support
This commit is contained in:
@@ -32,6 +32,25 @@ function removeLoraExtension(fileName = '') {
|
||||
return fileName.replace(/\.(safetensors|ckpt|pt|bin)$/i, '');
|
||||
}
|
||||
|
||||
function parseSearchTokens(term = '') {
|
||||
const include = [];
|
||||
const exclude = [];
|
||||
|
||||
term.split(/\s+/).forEach((rawTerm) => {
|
||||
const token = rawTerm.trim();
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
if (token.startsWith('-') && token.length > 1) {
|
||||
exclude.push(token.slice(1).toLowerCase());
|
||||
} else {
|
||||
include.push(token.toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
return { include, exclude };
|
||||
}
|
||||
|
||||
function createDefaultBehavior(modelType) {
|
||||
return {
|
||||
enablePreview: false,
|
||||
@@ -393,10 +412,20 @@ class AutoComplete {
|
||||
}
|
||||
|
||||
highlightMatch(text, searchTerm) {
|
||||
if (!searchTerm) return text;
|
||||
|
||||
const regex = new RegExp(`(${searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
|
||||
return text.replace(regex, '<span style="background-color: rgba(66, 153, 225, 0.3); color: white; padding: 1px 2px; border-radius: 2px;">$1</span>');
|
||||
const { include } = parseSearchTokens(searchTerm);
|
||||
const sanitizedTokens = include
|
||||
.filter(Boolean)
|
||||
.map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
||||
|
||||
if (!sanitizedTokens.length) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const regex = new RegExp(`(${sanitizedTokens.join('|')})`, 'gi');
|
||||
return text.replace(
|
||||
regex,
|
||||
'<span style="background-color: rgba(66, 153, 225, 0.3); color: white; padding: 1px 2px; border-radius: 2px;">$1</span>',
|
||||
);
|
||||
}
|
||||
|
||||
showPreviewForItem(relativePath, itemElement) {
|
||||
|
||||
Reference in New Issue
Block a user