From 8a02f62c701a3c25297cad82b66af5d06accca7a Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud <79562285+wangdan-fit2cloud@users.noreply.github.com> Date: Fri, 28 Feb 2025 16:47:48 +0800 Subject: [PATCH] perf: Optimization of chat input with line break when pressing enter --- .../ai-chat/component/chat-input-operate/index.vue | 14 ++++++++++++-- ui/src/styles/app.scss | 4 +--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ui/src/components/ai-chat/component/chat-input-operate/index.vue b/ui/src/components/ai-chat/component/chat-input-operate/index.vue index 44c986ebb..8329de818 100644 --- a/ui/src/components/ai-chat/component/chat-input-operate/index.vue +++ b/ui/src/components/ai-chat/component/chat-input-operate/index.vue @@ -535,10 +535,20 @@ function sendChatHandle(event?: any) { } } } else { - // 如果同时按下ctrl+回车键,则会换行 - inputValue.value += '\n' + // 如果同时按下ctrl+回车键,则会换行 + insertNewlineAtCursor() } } +const insertNewlineAtCursor = () => { + const textarea = document.querySelector('.el-textarea__inner') as HTMLTextAreaElement + const startPos = textarea.selectionStart + const endPos = textarea.selectionEnd + // 在光标处插入换行符 + inputValue.value = inputValue.value.slice(0, startPos) + '\n' + inputValue.value.slice(endPos) + nextTick(() => { + textarea.setSelectionRange(startPos + 1, startPos + 1) // 光标定位到换行后位置 + }) +} function deleteFile(index: number, val: string) { if (val === 'image') { diff --git a/ui/src/styles/app.scss b/ui/src/styles/app.scss index c42b4bf70..55f0106c2 100644 --- a/ui/src/styles/app.scss +++ b/ui/src/styles/app.scss @@ -11,9 +11,7 @@ margin: 0; padding: 0; } -[v-cloak] { - display: none !important; -} + html { height: 100%; box-sizing: border-box;