mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 01:50:13 +08:00
fix(inputbar): block enter send while generating (#11672)
* fix(inputbar): block enter send while generating - reuse unified send disable state for keyboard and button - prevent enter sending when loading or searching * refactor: optimize InputbarCore component's useHotkeys hook Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * refactor(InputbarCore): rename cannotSend to noContent for clarity --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
387e8f77f5
commit
fb20173194
@ -181,8 +181,10 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
enabled: config.enableDragDrop,
|
enabled: config.enableDragDrop,
|
||||||
t
|
t
|
||||||
})
|
})
|
||||||
// 判断是否可以发送:文本不为空或有文件
|
// 判断是否有内容:文本不为空或有文件
|
||||||
const cannotSend = isEmpty && files.length === 0
|
const noContent = isEmpty && files.length === 0
|
||||||
|
// 发送入口统一禁用条件:空内容、正在生成、全局搜索态
|
||||||
|
const isSendDisabled = noContent || isLoading || searching
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setExtensions(supportedExts)
|
setExtensions(supportedExts)
|
||||||
@ -313,7 +315,7 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
|
|
||||||
const isEnterPressed = event.key === 'Enter' && !event.nativeEvent.isComposing
|
const isEnterPressed = event.key === 'Enter' && !event.nativeEvent.isComposing
|
||||||
if (isEnterPressed) {
|
if (isEnterPressed) {
|
||||||
if (isSendMessageKeyPressed(event, sendMessageShortcut) && !cannotSend) {
|
if (isSendMessageKeyPressed(event, sendMessageShortcut) && !isSendDisabled) {
|
||||||
handleSendMessage()
|
handleSendMessage()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return
|
return
|
||||||
@ -359,7 +361,7 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
translate,
|
translate,
|
||||||
handleToggleExpanded,
|
handleToggleExpanded,
|
||||||
sendMessageShortcut,
|
sendMessageShortcut,
|
||||||
cannotSend,
|
isSendDisabled,
|
||||||
handleSendMessage,
|
handleSendMessage,
|
||||||
setText,
|
setText,
|
||||||
setTimeoutTimer,
|
setTimeoutTimer,
|
||||||
@ -620,7 +622,7 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
const rightSectionExtras = useMemo(() => {
|
const rightSectionExtras = useMemo(() => {
|
||||||
const extras: React.ReactNode[] = []
|
const extras: React.ReactNode[] = []
|
||||||
extras.push(<TranslateButton key="translate" text={text} onTranslated={onTranslated} isLoading={isTranslating} />)
|
extras.push(<TranslateButton key="translate" text={text} onTranslated={onTranslated} isLoading={isTranslating} />)
|
||||||
extras.push(<SendMessageButton sendMessage={handleSendMessage} disabled={cannotSend || isLoading || searching} />)
|
extras.push(<SendMessageButton sendMessage={handleSendMessage} disabled={isSendDisabled} />)
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
extras.push(
|
extras.push(
|
||||||
@ -633,7 +635,7 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <>{extras}</>
|
return <>{extras}</>
|
||||||
}, [text, onTranslated, isTranslating, handleSendMessage, cannotSend, isLoading, searching, t, onPause])
|
}, [text, onTranslated, isTranslating, handleSendMessage, isSendDisabled, isLoading, t, onPause])
|
||||||
|
|
||||||
const quickPanelElement = config.enableQuickPanel ? <QuickPanelView setInputText={setText} /> : null
|
const quickPanelElement = config.enableQuickPanel ? <QuickPanelView setInputText={setText} /> : null
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user