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:
Will Miao
2025-10-27 19:39:49 +08:00
parent 5326fa2970
commit 98678a8698
2 changed files with 64 additions and 1 deletions

View File

@@ -354,9 +354,11 @@ export function initReorderDrag(dragHandle, loraName, widget, renderFunction) {
// Function to handle keyboard navigation
export function handleKeyboardNavigation(event, selectedLora, widget, renderFunction, selectLora) {
if (!selectedLora) return false;
const lorasData = parseLoraValue(widget.value);
let handled = false;
const isStrengthInputFocused =
event?.target?.classList?.contains('lm-lora-strength-input') ?? false;
// Check for Ctrl/Cmd modifier for reordering
if (event.ctrlKey || event.metaKey) {
@@ -420,6 +422,9 @@ export function handleKeyboardNavigation(event, selectedLora, widget, renderFunc
case 'Delete':
case 'Backspace':
if (isStrengthInputFocused) {
break;
}
event.preventDefault();
const filtered = lorasData.filter(l => l.name !== selectedLora);
widget.value = formatLoraValue(filtered);