Skip to content

Commit

Permalink
设置划词翻译默认选中所有文本
Browse files Browse the repository at this point in the history
resolve pot-app#681
  • Loading branch information
AiSY-Yang committed Apr 2, 2024
1 parent 507c589 commit 6b702f4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/window/Translate/components/SourceArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -151,6 +153,7 @@ export default function SourceArea(props) {
syncSourceText();
});
}
setFirst(true);
};

const keyDown = (event) => {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 6b702f4

Please sign in to comment.