fix: handle multiple content source when pasting to translate input (#9919)

* fix(translate): 处理粘贴事件时增加处理中状态检查

* fix(translate): 修复粘贴文本时未阻止默认行为的问题

添加event.preventDefault()以防止粘贴文本时触发默认行为
同时优化粘贴逻辑,优先处理文本内容
This commit is contained in:
Phantom 2025-09-05 10:35:58 +08:00 committed by kangfenmao
parent 07c3c33acc
commit a5bfd8f3db

View File

@ -612,9 +612,14 @@ const TranslatePage: FC = () => {
// 粘贴上传文件
const onPaste = useCallback(
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
event.preventDefault()
if (isProcessing) return
setIsProcessing(true)
logger.debug('event', event)
if (event.clipboardData?.files && event.clipboardData.files.length > 0) {
const text = event.clipboardData.getData('text')
if (!isEmpty(text)) {
setText(text)
} else if (event.clipboardData.files && event.clipboardData.files.length > 0) {
event.preventDefault()
const files = event.clipboardData.files
const file = getSingleFile(files) as File
@ -659,7 +664,7 @@ const TranslatePage: FC = () => {
}
setIsProcessing(false)
},
[getSingleFile, processFile, t]
[getSingleFile, isProcessing, processFile, t]
)
return (
<Container