Skip to content

Commit ec5955d

Browse files
perf: Optimization of chat input with line break when pressing enter
1 parent 463ad49 commit ec5955d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,20 @@ function sendChatHandle(event?: any) {
535535
}
536536
}
537537
} else {
538-
// 如果同时按下ctrl+回车键,则会换行
539-
inputValue.value += '\n'
538+
// 如果同时按下ctrl+回车键,则会换行
539+
insertNewlineAtCursor()
540540
}
541541
}
542+
const insertNewlineAtCursor = () => {
543+
const textarea = document.querySelector('.el-textarea__inner') as HTMLTextAreaElement
544+
const startPos = textarea.selectionStart
545+
const endPos = textarea.selectionEnd
546+
// 在光标处插入换行符
547+
inputValue.value = inputValue.value.slice(0, startPos) + '\n' + inputValue.value.slice(endPos)
548+
nextTick(() => {
549+
textarea.setSelectionRange(startPos + 1, startPos + 1) // 光标定位到换行后位置
550+
})
551+
}
542552
543553
function deleteFile(index: number, val: string) {
544554
if (val === 'image') {

ui/src/styles/app.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
margin: 0;
1212
padding: 0;
1313
}
14-
[v-cloak] {
15-
display: none !important;
16-
}
14+
1715
html {
1816
height: 100%;
1917
box-sizing: border-box;

0 commit comments

Comments
 (0)