mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
refactor(ExampleImagesManager): enhance path input handling with Enter key and blur events
This commit is contained in:
@@ -94,11 +94,10 @@ export class ExampleImagesManager {
|
|||||||
|
|
||||||
// Add event listener to validate path input
|
// Add event listener to validate path input
|
||||||
if (pathInput) {
|
if (pathInput) {
|
||||||
pathInput.addEventListener('input', async () => {
|
// Save path on Enter key or blur
|
||||||
|
const savePath = async () => {
|
||||||
const hasPath = pathInput.value.trim() !== '';
|
const hasPath = pathInput.value.trim() !== '';
|
||||||
this.updateDownloadButtonState(hasPath);
|
this.updateDownloadButtonState(hasPath);
|
||||||
|
|
||||||
// Update path in backend settings using settingsManager
|
|
||||||
try {
|
try {
|
||||||
await settingsManager.saveSetting('example_images_path', pathInput.value);
|
await settingsManager.saveSetting('example_images_path', pathInput.value);
|
||||||
if (hasPath) {
|
if (hasPath) {
|
||||||
@@ -108,7 +107,6 @@ export class ExampleImagesManager {
|
|||||||
console.error('Failed to update example images path:', error);
|
console.error('Failed to update example images path:', error);
|
||||||
showToast('toast.exampleImages.pathUpdateFailed', { message: error.message }, 'error');
|
showToast('toast.exampleImages.pathUpdateFailed', { message: error.message }, 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup or clear auto download based on path availability
|
// Setup or clear auto download based on path availability
|
||||||
if (state.global.settings.autoDownloadExampleImages) {
|
if (state.global.settings.autoDownloadExampleImages) {
|
||||||
if (hasPath) {
|
if (hasPath) {
|
||||||
@@ -117,6 +115,26 @@ export class ExampleImagesManager {
|
|||||||
this.clearAutoDownload();
|
this.clearAutoDownload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
let ignoreNextBlur = false;
|
||||||
|
pathInput.addEventListener('keydown', async (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
ignoreNextBlur = true;
|
||||||
|
await savePath();
|
||||||
|
pathInput.blur(); // Remove focus from the input after saving
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pathInput.addEventListener('blur', async () => {
|
||||||
|
if (ignoreNextBlur) {
|
||||||
|
ignoreNextBlur = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await savePath();
|
||||||
|
});
|
||||||
|
// Still update button state on input, but don't save
|
||||||
|
pathInput.addEventListener('input', () => {
|
||||||
|
const hasPath = pathInput.value.trim() !== '';
|
||||||
|
this.updateDownloadButtonState(hasPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user