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": { "translate": {
"any.language": "Any language", "any.language": "Any language",
"button.translate": "Translate", "button.translate": "Translate",
"tooltip.newline": "Newline",
"close": "Close", "close": "Close",
"confirm": { "confirm": {
"content": "Translation will replace the original text, continue?", "content": "Translation will replace the original text, continue?",

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ import { fetchTranslate } from '@renderer/services/ApiService'
import { getDefaultTranslateAssistant } from '@renderer/services/AssistantService' import { getDefaultTranslateAssistant } from '@renderer/services/AssistantService'
import { Assistant, Message, TranslateHistory } from '@renderer/types' import { Assistant, Message, TranslateHistory } from '@renderer/types'
import { runAsyncFunction, uuid } from '@renderer/utils' 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 TextArea, { TextAreaRef } from 'antd/es/input/TextArea'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { useLiveQuery } from 'dexie-react-hooks' 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 = () => { const SettingButton = () => {
if (isLocalAi) { if (isLocalAi) {
return null return null
@ -244,14 +251,25 @@ const TranslatePage: FC = () => {
<SettingButton /> <SettingButton />
</Flex> </Flex>
<TranslateButton <Tooltip
type="primary" mouseEnterDelay={0.5}
loading={loading} styles={{ body: { fontSize: '12px' } }}
onClick={onTranslate} title={
disabled={!text.trim()} <div style={{ textAlign: 'center' }}>
icon={<SendOutlined />}> Enter: {t('translate.button.translate')}
{t('translate.button.translate')} <br />
</TranslateButton> Shift + Enter: {t('translate.tooltip.newline')}
</div>
}>
<TranslateButton
type="primary"
loading={loading}
onClick={onTranslate}
disabled={!text.trim()}
icon={<SendOutlined />}>
{t('translate.button.translate')}
</TranslateButton>
</Tooltip>
</OperationBar> </OperationBar>
<Textarea <Textarea
@ -260,6 +278,7 @@ const TranslatePage: FC = () => {
placeholder={t('translate.input.placeholder')} placeholder={t('translate.input.placeholder')}
value={text} value={text}
onChange={(e) => setText(e.target.value)} onChange={(e) => setText(e.target.value)}
onKeyDown={onKeyDown}
disabled={loading} disabled={loading}
spellCheck={false} spellCheck={false}
allowClear allowClear