diff --git a/frontend/src/lib/components/SavedInputsPicker.svelte b/frontend/src/lib/components/SavedInputsPicker.svelte index 4749c6745f..38b9df414f 100644 --- a/frontend/src/lib/components/SavedInputsPicker.svelte +++ b/frontend/src/lib/components/SavedInputsPicker.svelte @@ -162,7 +162,7 @@ function handleKeydown(event: KeyboardEvent) { if (event.key === 'Escape' && isEditing) { - setEditing(null) + setEditing(null, true) event.stopPropagation() event.preventDefault() } else if (event.key === 'Escape' && selectedInput) { @@ -172,15 +172,24 @@ } if (event.key === 'Enter' && isEditing) { + const session = editSession updateInput(isEditing).then(() => { - setEditing(null) + // a rename opened while this one was saving, even of the same row, stays open + if (editSession === session) setEditing(null) }) event.stopPropagation() event.preventDefault() } } - function setEditing(input: EditableInput | null) { + // The rename field edits the listed input itself, so a cancelled rename must put its name back, + // unless its save is in flight: that has already sent the new name. + let nameBeforeEdit = '' + let editSession = 0 + function setEditing(input: EditableInput | null, cancel = false) { + editSession++ + if (cancel && isEditing && !isEditing.isSaving) isEditing.name = nameBeforeEdit + nameBeforeEdit = input?.name ?? '' isEditing = input dispatch('isEditing', !!input) } @@ -331,7 +340,7 @@ updateInput(isEditing) setEditing(null) } else { - setEditing(item) + setEditing(item, true) } }} startIcon={{ icon: Pencil }}