Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/renderer/src/components/ChatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,12 @@ const props = withDefaults(
contextLength?: number
maxRows?: number
rows?: number
disabled?: boolean
}>(),
{
maxRows: 10,
rows: 1
rows: 1,
disabled: false
}
)

Expand Down Expand Up @@ -686,7 +688,7 @@ const emitSend = async () => {

emit('send', messageContent)
inputText.value = ''
editor.chain().clearContent().blur().run()
editor.chain().clearContent().run()

// 清除历史记录placeholder
clearHistoryPlaceholder()
Expand All @@ -700,6 +702,9 @@ const emitSend = async () => {
fileInput.value.value = ''
}
}
nextTick(() => {
editor.commands.focus()
})
}
}

Expand Down Expand Up @@ -982,6 +987,14 @@ onMounted(() => {
editor.commands.focus()
})

document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
setTimeout(() => {
restoreFocus()
}, 100)
}
})

window.electron.ipcRenderer.on('rate-limit:config-updated', handleRateLimitEvent)
window.electron.ipcRenderer.on('rate-limit:request-executed', handleRateLimitEvent)
window.electron.ipcRenderer.on('rate-limit:request-queued', handleRateLimitEvent)
Expand Down Expand Up @@ -1090,6 +1103,17 @@ watch(dynamicPlaceholder, () => {
updatePlaceholder()
})

watch(
() => props.disabled,
(newDisabled, oldDisabled) => {
if (oldDisabled && !newDisabled) {
setTimeout(() => {
restoreFocus()
}, 100)
}
}
)

// 处理历史记录placeholder
const setHistoryPlaceholder = (text: string) => {
currentHistoryPlaceholder.value = text
Expand Down Expand Up @@ -1157,6 +1181,21 @@ function onKeydown(e: KeyboardEvent) {
}
}

const restoreFocus = () => {
nextTick(() => {
if (editor && !editor.isDestroyed && !props.disabled) {
try {
const editorElement = editor.view.dom
if (editorElement && editorElement.offsetParent !== null) {
editor.commands.focus()
}
} catch (error) {
console.warn('恢复焦点时出错:', error)
}
}
})
}

// 通过名称查找mention数据
const findMentionByName = (name: string): CategorizedData | null => {
// 在当前的mentionData中查找匹配的项目
Expand Down Expand Up @@ -1261,7 +1300,8 @@ defineExpose({
console.error('Failed to append mention:', error)
return false
}
}
},
restoreFocus
})
</script>

Expand Down
12 changes: 12 additions & 0 deletions src/renderer/src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<!-- 输入框区域 -->
<div class="flex-none px-2 pb-2">
<ChatInput
ref="chatInput"
:disabled="!chatStore.getActiveThreadId() || isGenerating"
@send="handleSend"
@file-upload="handleFileUpload"
Expand All @@ -32,6 +33,7 @@ const route = useRoute()
const settingsStore = useSettingsStore()

const messageList = ref()
const chatInput = ref()

import { useChatStore } from '@/stores/chat'

Expand All @@ -48,6 +50,10 @@ const handleSend = async (msg: UserMessageContent) => {
scrollToBottom()
await chatStore.sendMessage(msg)
scrollToBottom()

setTimeout(() => {
chatInput.value?.restoreFocus()
}, 100)
}

const handleFileUpload = () => {
Expand All @@ -63,10 +69,16 @@ onMounted(async () => {

window.electron.ipcRenderer.on(STREAM_EVENTS.END, (_, msg) => {
chatStore.handleStreamEnd(msg)
setTimeout(() => {
chatInput.value?.restoreFocus()
}, 200)
})

window.electron.ipcRenderer.on(STREAM_EVENTS.ERROR, (_, msg) => {
chatStore.handleStreamError(msg)
setTimeout(() => {
chatInput.value?.restoreFocus()
}, 200)
})

if (route.query.modelId && route.query.providerId) {
Expand Down