mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 22:52:12 -03:00
fix(settings): Auto-scroll to first search match in settings modal
When searching in settings, the view now automatically scrolls to the first matching element after switching to the matching section. - Modified performSearch() to track and scroll to first match - Modified highlightSearchMatches() to return the first highlight element - Uses requestAnimationFrame and scrollIntoView with block: 'center'
This commit is contained in:
@@ -476,6 +476,7 @@ export class SettingsManager {
|
|||||||
|
|
||||||
const lowerQuery = query.toLowerCase();
|
const lowerQuery = query.toLowerCase();
|
||||||
let firstMatchSection = null;
|
let firstMatchSection = null;
|
||||||
|
let firstMatchElement = null;
|
||||||
let matchCount = 0;
|
let matchCount = 0;
|
||||||
|
|
||||||
sections.forEach(section => {
|
sections.forEach(section => {
|
||||||
@@ -483,12 +484,13 @@ export class SettingsManager {
|
|||||||
const hasMatch = sectionText.includes(lowerQuery);
|
const hasMatch = sectionText.includes(lowerQuery);
|
||||||
|
|
||||||
if (hasMatch) {
|
if (hasMatch) {
|
||||||
this.highlightSearchMatches(section, lowerQuery);
|
const firstHighlight = this.highlightSearchMatches(section, lowerQuery);
|
||||||
matchCount++;
|
matchCount++;
|
||||||
|
|
||||||
// Track first match to auto-switch
|
// Track first match to auto-switch
|
||||||
if (!firstMatchSection) {
|
if (!firstMatchSection) {
|
||||||
firstMatchSection = section;
|
firstMatchSection = section;
|
||||||
|
firstMatchElement = firstHighlight;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.removeSearchHighlights(section);
|
this.removeSearchHighlights(section);
|
||||||
@@ -512,6 +514,16 @@ export class SettingsManager {
|
|||||||
item.classList.add('active');
|
item.classList.add('active');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Scroll to first match after a short delay to allow section to become visible
|
||||||
|
if (firstMatchElement) {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
firstMatchElement.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'center'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show empty state if no matches found
|
// Show empty state if no matches found
|
||||||
@@ -545,10 +557,11 @@ export class SettingsManager {
|
|||||||
// Remove existing highlights first
|
// Remove existing highlights first
|
||||||
this.removeSearchHighlights(section);
|
this.removeSearchHighlights(section);
|
||||||
|
|
||||||
if (!query) return;
|
if (!query) return null;
|
||||||
|
|
||||||
// Highlight in labels and help text
|
// Highlight in labels and help text
|
||||||
const textElements = section.querySelectorAll('label, .input-help, h3');
|
const textElements = section.querySelectorAll('label, .input-help, h3');
|
||||||
|
let firstHighlight = null;
|
||||||
|
|
||||||
textElements.forEach(element => {
|
textElements.forEach(element => {
|
||||||
const walker = document.createTreeWalker(
|
const walker = document.createTreeWalker(
|
||||||
@@ -588,6 +601,11 @@ export class SettingsManager {
|
|||||||
highlight.textContent = text.substring(index, index + query.length);
|
highlight.textContent = text.substring(index, index + query.length);
|
||||||
parts.push(highlight);
|
parts.push(highlight);
|
||||||
|
|
||||||
|
// Track first highlight for scrolling
|
||||||
|
if (!firstHighlight) {
|
||||||
|
firstHighlight = highlight;
|
||||||
|
}
|
||||||
|
|
||||||
lastIndex = index + query.length;
|
lastIndex = index + query.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,6 +621,8 @@ export class SettingsManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return firstHighlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSearchHighlights(section) {
|
removeSearchHighlights(section) {
|
||||||
|
|||||||
Reference in New Issue
Block a user