mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 22:52:12 -03:00
fix: Disable virtual scroll keyboard navigation when editing content or a modal is open. See #759
This commit is contained in:
@@ -9,7 +9,7 @@ async function getCardCreator(pageType) {
|
|||||||
if (pageType === 'recipes') {
|
if (pageType === 'recipes') {
|
||||||
// Import the RecipeCard module
|
// Import the RecipeCard module
|
||||||
const { RecipeCard } = await import('../components/RecipeCard.js');
|
const { RecipeCard } = await import('../components/RecipeCard.js');
|
||||||
|
|
||||||
// Return a wrapper function that creates a recipe card element
|
// Return a wrapper function that creates a recipe card element
|
||||||
return (recipe) => {
|
return (recipe) => {
|
||||||
const recipeCard = new RecipeCard(recipe, (recipe) => {
|
const recipeCard = new RecipeCard(recipe, (recipe) => {
|
||||||
@@ -47,10 +47,10 @@ export async function initializeInfiniteScroll(pageType = 'loras') {
|
|||||||
|
|
||||||
// Set the current page type
|
// Set the current page type
|
||||||
state.currentPageType = pageType;
|
state.currentPageType = pageType;
|
||||||
|
|
||||||
// Get the current page state
|
// Get the current page state
|
||||||
const pageState = getCurrentPageState();
|
const pageState = getCurrentPageState();
|
||||||
|
|
||||||
// Skip initializing if in duplicates mode (for recipes page)
|
// Skip initializing if in duplicates mode (for recipes page)
|
||||||
if (pageType === 'recipes' && pageState.duplicatesMode) {
|
if (pageType === 'recipes' && pageState.duplicatesMode) {
|
||||||
console.log('Skipping virtual scroll initialization - duplicates mode is active');
|
console.log('Skipping virtual scroll initialization - duplicates mode is active');
|
||||||
@@ -59,7 +59,7 @@ export async function initializeInfiniteScroll(pageType = 'loras') {
|
|||||||
|
|
||||||
// Use virtual scrolling for all page types
|
// Use virtual scrolling for all page types
|
||||||
await initializeVirtualScroll(pageType);
|
await initializeVirtualScroll(pageType);
|
||||||
|
|
||||||
// Setup event delegation for model cards based on page type
|
// Setup event delegation for model cards based on page type
|
||||||
setupModelCardEventDelegation(pageType);
|
setupModelCardEventDelegation(pageType);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ export async function initializeInfiniteScroll(pageType = 'loras') {
|
|||||||
async function initializeVirtualScroll(pageType) {
|
async function initializeVirtualScroll(pageType) {
|
||||||
// Determine the grid ID based on page type
|
// Determine the grid ID based on page type
|
||||||
let gridId;
|
let gridId;
|
||||||
|
|
||||||
switch (pageType) {
|
switch (pageType) {
|
||||||
case 'recipes':
|
case 'recipes':
|
||||||
gridId = 'recipeGrid';
|
gridId = 'recipeGrid';
|
||||||
@@ -80,30 +80,30 @@ async function initializeVirtualScroll(pageType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const grid = document.getElementById(gridId);
|
const grid = document.getElementById(gridId);
|
||||||
|
|
||||||
if (!grid) {
|
if (!grid) {
|
||||||
console.warn(`Grid with ID "${gridId}" not found for virtual scroll`);
|
console.warn(`Grid with ID "${gridId}" not found for virtual scroll`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change this line to get the actual scrolling container
|
// Change this line to get the actual scrolling container
|
||||||
const scrollContainer = document.querySelector('.page-content');
|
const scrollContainer = document.querySelector('.page-content');
|
||||||
const gridContainer = scrollContainer.querySelector('.container');
|
const gridContainer = scrollContainer.querySelector('.container');
|
||||||
|
|
||||||
if (!gridContainer) {
|
if (!gridContainer) {
|
||||||
console.warn('Grid container element not found for virtual scroll');
|
console.warn('Grid container element not found for virtual scroll');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the card creator and data fetcher for this page type
|
// Get the card creator and data fetcher for this page type
|
||||||
const createCardFn = await getCardCreator(pageType);
|
const createCardFn = await getCardCreator(pageType);
|
||||||
const fetchDataFn = await getDataFetcher(pageType);
|
const fetchDataFn = await getDataFetcher(pageType);
|
||||||
|
|
||||||
if (!createCardFn || !fetchDataFn) {
|
if (!createCardFn || !fetchDataFn) {
|
||||||
throw new Error(`Required components not available for ${pageType} page`);
|
throw new Error(`Required components not available for ${pageType} page`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize virtual scroller with renamed container elements
|
// Initialize virtual scroller with renamed container elements
|
||||||
state.virtualScroller = new VirtualScroller({
|
state.virtualScroller = new VirtualScroller({
|
||||||
gridElement: grid,
|
gridElement: grid,
|
||||||
@@ -117,20 +117,20 @@ async function initializeVirtualScroll(pageType) {
|
|||||||
containerPaddingBottom: 4,
|
containerPaddingBottom: 4,
|
||||||
enableDataWindowing: false // Explicitly set to false to disable data windowing
|
enableDataWindowing: false // Explicitly set to false to disable data windowing
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize the virtual scroller
|
// Initialize the virtual scroller
|
||||||
await state.virtualScroller.initialize();
|
await state.virtualScroller.initialize();
|
||||||
|
|
||||||
// Add grid class for CSS styling
|
// Add grid class for CSS styling
|
||||||
grid.classList.add('virtual-scroll');
|
grid.classList.add('virtual-scroll');
|
||||||
|
|
||||||
// Setup keyboard navigation
|
// Setup keyboard navigation
|
||||||
setupKeyboardNavigation();
|
setupKeyboardNavigation();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error initializing virtual scroller for ${pageType}:`, error);
|
console.error(`Error initializing virtual scroller for ${pageType}:`, error);
|
||||||
showToast('toast.general.pageInitFailed', { pageType }, 'error');
|
showToast('toast.general.pageInitFailed', { pageType }, 'error');
|
||||||
|
|
||||||
// Fallback: show a message in the grid
|
// Fallback: show a message in the grid
|
||||||
grid.innerHTML = `
|
grid.innerHTML = `
|
||||||
<div class="placeholder-message">
|
<div class="placeholder-message">
|
||||||
@@ -146,17 +146,20 @@ function setupKeyboardNavigation() {
|
|||||||
// Keep track of the last keypress time to prevent multiple rapid triggers
|
// Keep track of the last keypress time to prevent multiple rapid triggers
|
||||||
let lastKeyTime = 0;
|
let lastKeyTime = 0;
|
||||||
const keyDelay = 300; // ms between allowed keypresses
|
const keyDelay = 300; // ms between allowed keypresses
|
||||||
|
|
||||||
// Store the event listener reference so we can remove it later if needed
|
// Store the event listener reference so we can remove it later if needed
|
||||||
const keyboardNavHandler = (event) => {
|
const keyboardNavHandler = (event) => {
|
||||||
// Only handle keyboard events when not in form elements
|
// Only handle keyboard events when not in form elements or contenteditable elements
|
||||||
if (event.target.matches('input, textarea, select')) return;
|
if (event.target.matches('input, textarea, select') || event.target.isContentEditable) return;
|
||||||
|
|
||||||
|
// Skip background navigation if a modal is open
|
||||||
|
if (document.body.classList.contains('modal-open')) return;
|
||||||
|
|
||||||
// Prevent rapid keypresses
|
// Prevent rapid keypresses
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastKeyTime < keyDelay) return;
|
if (now - lastKeyTime < keyDelay) return;
|
||||||
lastKeyTime = now;
|
lastKeyTime = now;
|
||||||
|
|
||||||
// Handle navigation keys
|
// Handle navigation keys
|
||||||
if (event.key === 'PageUp') {
|
if (event.key === 'PageUp') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -180,10 +183,10 @@ function setupKeyboardNavigation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the event listener
|
// Add the event listener
|
||||||
document.addEventListener('keydown', keyboardNavHandler);
|
document.addEventListener('keydown', keyboardNavHandler);
|
||||||
|
|
||||||
// Store the handler in state for potential cleanup
|
// Store the handler in state for potential cleanup
|
||||||
state.keyboardNavHandler = keyboardNavHandler;
|
state.keyboardNavHandler = keyboardNavHandler;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user