diff --git a/frontend/src/pages/Chat/Chat.jsx b/frontend/src/pages/Chat/Chat.jsx index 6b47b1c..17d0baa 100644 --- a/frontend/src/pages/Chat/Chat.jsx +++ b/frontend/src/pages/Chat/Chat.jsx @@ -17,6 +17,7 @@ import { Typography, } from 'antd' import Toast from '@/components/Toast/Toast' +import { useImeSafeEnter } from '@/utils/ime' import { FolderOutlined, EditOutlined, @@ -1032,6 +1033,12 @@ function Chat() { } } + // 输入框/文本域的回车提交:输入法组合中的回车留给输入法选词, + // 避免「拼音打完按回车选词」把还没上屏的半截文本直接发送或搜索出去 + const composerImeSubmit = useImeSafeEnter(handleSend, { allowCtrlMeta: true }) + const newSessionImeSubmit = useImeSafeEnter(handleCreateSession, { allowCtrlMeta: true }) + const searchImeSubmit = useImeSafeEnter(handleSearch) + const handleSelectSearchResult = async (item) => { setSearchVisible(false) await openSession(item.session_id, { message_id: item.message_id }) @@ -1361,12 +1368,7 @@ function Chat() { onChange={(e) => setInputValue(e.target.value)} autoSize={{ minRows: 1, maxRows: 8 }} placeholder="随心输入" - onPressEnter={(e) => { - if (!e.shiftKey) { - e.preventDefault() - handleSend() - } - }} + {...composerImeSubmit} />
@@ -1448,12 +1450,7 @@ function Chat() { autoFocus autoSize={{ minRows: 2, maxRows: 10 }} placeholder="随心输入" - onPressEnter={(e) => { - if (!e.shiftKey) { - e.preventDefault() - handleCreateSession() - } - }} + {...newSessionImeSubmit} />
@@ -1567,7 +1564,7 @@ function Chat() { onChange={handleSearchKeywordChange} placeholder="输入聊天关键词,仅搜索对话内容" allowClear - onPressEnter={handleSearch} + {...searchImeSubmit} />