Browse Source

feat: submit chat title rename with Enter, cancel with ESC

hurxxxx 3 months ago
parent
commit
3b624f35ac
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/lib/components/layout/Sidebar/ChatItem.svelte

+ 14 - 0
src/lib/components/layout/Sidebar/ChatItem.svelte

@@ -198,6 +198,19 @@
 	});
 
 	let showDeleteConfirm = false;
+
+	const keyDownEvent = (e) => {
+		if (e.key === 'Enter') {
+			e.preventDefault();
+			editChatTitle(id, chatTitle);
+			confirmEdit = false;
+			chatTitle = '';
+		} else if (e.key === 'Escape') {
+			e.preventDefault();
+			confirmEdit = false;
+			chatTitle = '';
+		}
+	};
 </script>
 
 <ShareChatModal bind:show={showShareChatModal} chatId={id} />
@@ -246,6 +259,7 @@
 				bind:value={chatTitle}
 				id="chat-title-input-{id}"
 				class=" bg-transparent w-full outline-hidden mr-10"
+				on:keydown={keyDownEvent}
 			/>
 		</div>
 	{:else}