mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 06:19:05 +08:00
fix: handle multiple content source when pasting to translate input (#9919)
* fix(translate): 处理粘贴事件时增加处理中状态检查 * fix(translate): 修复粘贴文本时未阻止默认行为的问题 添加event.preventDefault()以防止粘贴文本时触发默认行为 同时优化粘贴逻辑,优先处理文本内容
This commit is contained in:
parent
fd0645fbb4
commit
e9db53c973
@ -612,9 +612,14 @@ const TranslatePage: FC = () => {
|
|||||||
// 粘贴上传文件
|
// 粘贴上传文件
|
||||||
const onPaste = useCallback(
|
const onPaste = useCallback(
|
||||||
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
event.preventDefault()
|
||||||
|
if (isProcessing) return
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
logger.debug('event', event)
|
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()
|
event.preventDefault()
|
||||||
const files = event.clipboardData.files
|
const files = event.clipboardData.files
|
||||||
const file = getSingleFile(files) as File
|
const file = getSingleFile(files) as File
|
||||||
@ -659,7 +664,7 @@ const TranslatePage: FC = () => {
|
|||||||
}
|
}
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
},
|
},
|
||||||
[getSingleFile, processFile, t]
|
[getSingleFile, isProcessing, processFile, t]
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user