From aa374823ce7f2715d52d0f2c5071d2aee49add4d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 5 May 2025 10:16:34 +0400 Subject: [PATCH] refac --- .../components/layout/Sidebar/ChatItem.svelte | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index bc3b56b30..19c19cd3d 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -66,7 +66,6 @@ let showShareChatModal = false; let confirmEdit = false; - let editInputFocused = false; let chatTitle = title; @@ -137,6 +136,7 @@ let itemElement; + let doubleClicked = false; let dragged = false; let x = 0; let y = 0; @@ -212,19 +212,17 @@ } }; - const focusEditInput = async () => { - console.log('focusEditInput'); + const renameHandler = async () => { + chatTitle = title; + confirmEdit = true; + await tick(); - const input = document.getElementById(`chat-title-input-${id}`); - if (input) { - input.focus(); - } + setTimeout(() => { + const input = document.getElementById(`chat-title-input-${id}`); + if (input) input.focus(); + }, 0); }; - - $: if (confirmEdit) { - focusEditInput(); - } @@ -273,18 +271,27 @@ bind:value={chatTitle} class=" bg-transparent w-full outline-hidden mr-10" on:keydown={chatTitleInputKeydownHandler} - on:focus={() => { - editInputFocused = true; - }} - on:blur={() => { - if (editInputFocused) { - if (chatTitle !== title) { - editChatTitle(id, chatTitle); - } + on:blur={async (e) => { + if (doubleClicked) { + e.preventDefault(); + e.stopPropagation(); - confirmEdit = false; - chatTitle = ''; + await tick(); + setTimeout(() => { + const input = document.getElementById(`chat-title-input-${id}`); + if (input) input.focus(); + }, 0); + + doubleClicked = false; + return; } + + if (chatTitle !== title) { + editChatTitle(id, chatTitle); + } + + confirmEdit = false; + chatTitle = ''; }} /> @@ -304,9 +311,12 @@ showSidebar.set(false); } }} - on:dblclick={() => { - chatTitle = title; - confirmEdit = true; + on:dblclick={async (e) => { + e.preventDefault(); + e.stopPropagation(); + + doubleClicked = true; + renameHandler(); }} on:mouseenter={(e) => { mouseOver = true; @@ -394,16 +404,7 @@ archiveChatHandler={() => { archiveChatHandler(id); }} - renameHandler={async () => { - chatTitle = title; - confirmEdit = true; - - await tick(); - const input = document.getElementById(`chat-title-input-${id}`); - if (input) { - input.focus(); - } - }} + {renameHandler} deleteHandler={() => { showDeleteConfirm = true; }}