Skip to content

Commit f62d7f2

Browse files
authored
Merge pull request #379 from iceljc/features/refine-chat-window
refine chat text area focus
2 parents e6bfc8c + 0ac3be6 commit f62d7f2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@
215215
// const editor = lastBotMsg?.rich_content?.editor || '';
216216
loadTextEditor = true; // TEXT_EDITORS.includes(editor) || !Object.values(EditorType).includes(editor);
217217
loadEditor = !isSendingMsg && !isThinking && loadTextEditor && messageQueue.length === 0;
218+
if (loadEditor) {
219+
focusChatTextArea();
220+
}
218221
}
219222
220223
$: {
@@ -270,12 +273,26 @@
270273
handleChatAction(e);
271274
}
272275
});
276+
277+
await focusChatTextArea();
273278
});
274279
275280
function handleLogoutAction() {
276281
resetLocalStorage(true);
277282
}
278283
284+
function focusChatTextArea() {
285+
return new Promise(resolve => {
286+
tick().then(() => {
287+
const textarea = document.getElementById('chat-textarea');
288+
if (textarea) {
289+
textarea.focus();
290+
}
291+
resolve('focused');
292+
});
293+
});
294+
}
295+
279296
/** @param {any} e */
280297
function handleNewChatAction(e) {
281298
if (!isCreatingNewConv && !isThinking && !isSendingMsg) {
@@ -1947,6 +1964,7 @@
19471964
<div class="col">
19481965
<div class="position-relative">
19491966
<ChatTextArea
1967+
id={'chat-textarea'}
19501968
className={`chat-input ${!isLite ? 'chat-more-util' : ''}`}
19511969
maxLength={maxTextLength}
19521970
disabled={isSendingMsg || isThinking || disableAction}

src/routes/chat/[agentId]/[conversationId]/chat-util/chat-text-area.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import { clickoutsideDirective } from "$lib/helpers/directives";
33
import _ from "lodash";
44
5+
/** @type {string} */
6+
export let id;
7+
58
/** @type {string} */
69
export let className = '';
710
@@ -110,6 +113,7 @@
110113
</div>
111114
{/if}
112115
<textarea
116+
id={id}
113117
class={`form-control ${className}`}
114118
rows={rows}
115119
maxlength={maxLength}

src/routes/page/dashboard/Conversation.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<div class="col-10">
121121
<div class="position-relative">
122122
<ChatTextArea
123+
id={'dashboard-chat-textarea'}
123124
className={`chat-input`}
124125
maxLength={1024}
125126
disabled={false}

0 commit comments

Comments
 (0)