From 507c589fb533a82f01663106ea4c572186460417 Mon Sep 17 00:00:00 2001 From: AiSY-Yang <978854518@qq.com> Date: Tue, 2 Apr 2024 15:58:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8F=A5=E9=A6=96=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/window/Translate/components/SourceArea/index.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/window/Translate/components/SourceArea/index.jsx b/src/window/Translate/components/SourceArea/index.jsx index 3c84442377..4cd2e21c33 100644 --- a/src/window/Translate/components/SourceArea/index.jsx +++ b/src/window/Translate/components/SourceArea/index.jsx @@ -141,7 +141,8 @@ export default function SourceArea(props) { } if (incrementalTranslate) { setSourceText((old) => { - return old + ' ' + newText; + //增量翻译的时候 如果原来没有内容 则直接设置内容 避免文章开头出现空格 + return old == '' ? newText : old + ' ' + newText; }); } else { setSourceText(newText); From 6b702f48368dbc2ae6fcc0462a6e5f237401d083 Mon Sep 17 00:00:00 2001 From: AiSY-Yang <978854518@qq.com> Date: Tue, 2 Apr 2024 16:00:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=88=92=E8=AF=8D?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #681 --- src/window/Translate/components/SourceArea/index.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/window/Translate/components/SourceArea/index.jsx b/src/window/Translate/components/SourceArea/index.jsx index 4cd2e21c33..4f497e371a 100644 --- a/src/window/Translate/components/SourceArea/index.jsx +++ b/src/window/Translate/components/SourceArea/index.jsx @@ -45,6 +45,8 @@ export default function SourceArea(props) { const { t } = useTranslation(); const textAreaRef = useRef(); const speak = useVoice(); + // 是否是首次打开页面 首次打开页面时全选内容 这样可以将'划词翻译'和'输入翻译'合并为一个功能 + const [first, setFirst] = useState(false); const handleNewText = async (text) => { text = text.trim(); @@ -151,6 +153,7 @@ export default function SourceArea(props) { syncSourceText(); }); } + setFirst(true); }; const keyDown = (event) => { @@ -239,6 +242,9 @@ export default function SourceArea(props) { textAreaRef.current.style.height = '50px'; textAreaRef.current.style.height = textAreaRef.current.scrollHeight + 'px'; }, [sourceText]); + useEffect(() => { + textAreaRef.current.select(); + }, [first]); const detect_language = async (text) => { setDetectLanguage(await detect(text));