feat: Add newline tooltip for translation input

This commit is contained in:
ousugo 2025-02-21 10:25:01 +08:00 committed by 亢奋猫
parent 369f629206
commit 6a57973864
6 changed files with 33 additions and 9 deletions

View File

@ -780,6 +780,7 @@
"translate": {
"any.language": "Any language",
"button.translate": "Translate",
"tooltip.newline": "Newline",
"close": "Close",
"confirm": {
"content": "Translation will replace the original text, continue?",

View File

@ -791,6 +791,7 @@
"translate": {
"any.language": "任意の言語",
"button.translate": "翻訳",
"tooltip.newline": "改行",
"close": "閉じる",
"confirm": {
"content": "翻訳すると元のテキストが上書きされます。続行しますか?",

View File

@ -770,6 +770,7 @@
"translate": {
"any.language": "Любой язык",
"button.translate": "Перевести",
"tooltip.newline": "Перевести",
"close": "Закрыть",
"confirm": {
"content": "Перевод заменит исходный текст, продолжить?",

View File

@ -783,6 +783,7 @@
"translate": {
"any.language": "任意语言",
"button.translate": "翻译",
"tooltip.newline": "换行",
"close": "关闭",
"confirm": {
"content": "翻译后将覆盖原文,是否继续?",

View File

@ -772,6 +772,7 @@
"translate": {
"any.language": "任意語言",
"button.translate": "翻譯",
"tooltip.newline": "換行",
"close": "關閉",
"confirm": {
"content": "翻譯後將覆蓋原文,是否繼續?",

View File

@ -16,7 +16,7 @@ import { fetchTranslate } from '@renderer/services/ApiService'
import { getDefaultTranslateAssistant } from '@renderer/services/AssistantService'
import { Assistant, Message, TranslateHistory } from '@renderer/types'
import { runAsyncFunction, uuid } from '@renderer/utils'
import { Button, Dropdown, Empty, Flex, Popconfirm, Select, Space } from 'antd'
import { Button, Dropdown, Empty, Flex, Popconfirm, Select, Space, Tooltip } from 'antd'
import TextArea, { TextAreaRef } from 'antd/es/input/TextArea'
import dayjs from 'dayjs'
import { useLiveQuery } from 'dexie-react-hooks'
@ -139,6 +139,13 @@ const TranslatePage: FC = () => {
})
}, [])
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
e.preventDefault()
onTranslate()
}
}
const SettingButton = () => {
if (isLocalAi) {
return null
@ -244,6 +251,16 @@ const TranslatePage: FC = () => {
<SettingButton />
</Flex>
<Tooltip
mouseEnterDelay={0.5}
styles={{ body: { fontSize: '12px' } }}
title={
<div style={{ textAlign: 'center' }}>
Enter: {t('translate.button.translate')}
<br />
Shift + Enter: {t('translate.tooltip.newline')}
</div>
}>
<TranslateButton
type="primary"
loading={loading}
@ -252,6 +269,7 @@ const TranslatePage: FC = () => {
icon={<SendOutlined />}>
{t('translate.button.translate')}
</TranslateButton>
</Tooltip>
</OperationBar>
<Textarea
@ -260,6 +278,7 @@ const TranslatePage: FC = () => {
placeholder={t('translate.input.placeholder')}
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={onKeyDown}
disabled={loading}
spellCheck={false}
allowClear