mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 23:25:43 -03:00
feat(loras): add backspace key handling for LoRA deletion with input focus check, fixes #601
Add keyboard navigation support for deleting selected LoRA entries using Backspace key while preventing accidental deletion when editing strength input values. The implementation includes: - Backspace key now deletes selected LoRA when pressed outside strength inputs - Backspace is ignored when focused on strength input fields to allow normal text editing - Added corresponding test cases to verify both deletion and non-deletion scenarios This prevents users from accidentally deleting LoRA entries while editing strength values and provides intuitive keyboard controls for LoRA management.
This commit is contained in:
@@ -105,4 +105,62 @@ describe('LoRA widget drag interactions', () => {
|
|||||||
document.dispatchEvent(new MouseEvent('mouseup'));
|
document.dispatchEvent(new MouseEvent('mouseup'));
|
||||||
expect(document.body.classList.contains('lm-lora-strength-dragging')).toBe(false);
|
expect(document.body.classList.contains('lm-lora-strength-dragging')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('deletes the selected LoRA when backspace is pressed outside of strength inputs', async () => {
|
||||||
|
const { handleKeyboardNavigation } = await import(EVENTS_MODULE);
|
||||||
|
const widget = {
|
||||||
|
value: [{ name: 'Test', strength: 0.5, clipStrength: 0.5 }],
|
||||||
|
callback: vi.fn(),
|
||||||
|
};
|
||||||
|
const preventDefault = vi.fn();
|
||||||
|
const renderSpy = vi.fn();
|
||||||
|
const selectLora = vi.fn();
|
||||||
|
const event = {
|
||||||
|
key: 'Backspace',
|
||||||
|
preventDefault,
|
||||||
|
ctrlKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
target: document.createElement('div'),
|
||||||
|
};
|
||||||
|
|
||||||
|
const handled = handleKeyboardNavigation(event, 'Test', widget, renderSpy, selectLora);
|
||||||
|
|
||||||
|
expect(handled).toBe(true);
|
||||||
|
expect(preventDefault).toHaveBeenCalled();
|
||||||
|
expect(widget.value).toEqual([]);
|
||||||
|
expect(widget.callback).toHaveBeenCalledWith([]);
|
||||||
|
expect(renderSpy).toHaveBeenCalledWith([], widget);
|
||||||
|
expect(selectLora).toHaveBeenCalledWith(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the LoRA entry when editing strength input and pressing backspace', async () => {
|
||||||
|
const { handleKeyboardNavigation } = await import(EVENTS_MODULE);
|
||||||
|
const strengthInput = document.createElement('input');
|
||||||
|
strengthInput.classList.add('lm-lora-strength-input');
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
value: [{ name: 'Test', strength: 0.5, clipStrength: 0.5 }],
|
||||||
|
callback: vi.fn(),
|
||||||
|
};
|
||||||
|
const preventDefault = vi.fn();
|
||||||
|
const renderSpy = vi.fn();
|
||||||
|
const selectLora = vi.fn();
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
key: 'Backspace',
|
||||||
|
preventDefault,
|
||||||
|
ctrlKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
target: strengthInput,
|
||||||
|
};
|
||||||
|
|
||||||
|
const handled = handleKeyboardNavigation(event, 'Test', widget, renderSpy, selectLora);
|
||||||
|
|
||||||
|
expect(handled).toBe(false);
|
||||||
|
expect(preventDefault).not.toHaveBeenCalled();
|
||||||
|
expect(widget.value).toHaveLength(1);
|
||||||
|
expect(widget.callback).not.toHaveBeenCalled();
|
||||||
|
expect(renderSpy).not.toHaveBeenCalled();
|
||||||
|
expect(selectLora).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -357,6 +357,8 @@ export function handleKeyboardNavigation(event, selectedLora, widget, renderFunc
|
|||||||
|
|
||||||
const lorasData = parseLoraValue(widget.value);
|
const lorasData = parseLoraValue(widget.value);
|
||||||
let handled = false;
|
let handled = false;
|
||||||
|
const isStrengthInputFocused =
|
||||||
|
event?.target?.classList?.contains('lm-lora-strength-input') ?? false;
|
||||||
|
|
||||||
// Check for Ctrl/Cmd modifier for reordering
|
// Check for Ctrl/Cmd modifier for reordering
|
||||||
if (event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
@@ -420,6 +422,9 @@ export function handleKeyboardNavigation(event, selectedLora, widget, renderFunc
|
|||||||
|
|
||||||
case 'Delete':
|
case 'Delete':
|
||||||
case 'Backspace':
|
case 'Backspace':
|
||||||
|
if (isStrengthInputFocused) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const filtered = lorasData.filter(l => l.name !== selectedLora);
|
const filtered = lorasData.filter(l => l.name !== selectedLora);
|
||||||
widget.value = formatLoraValue(filtered);
|
widget.value = formatLoraValue(filtered);
|
||||||
|
|||||||
Reference in New Issue
Block a user