num of newline characters

This commit is contained in:
Gabe Yuan
2023-09-01 11:21:06 +08:00
parent cde7a1d49f
commit 3e36ceb5b9
4 changed files with 25 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import {
DEFAULT_COLOR,
EVENT_KISS,
MSG_TRANS_CURRULE,
TRANS_NEWLINE_LENGTH,
} from "../../config";
import { useTranslate } from "../../hooks/Translate";
@@ -19,6 +20,8 @@ export default function Content({ q, translator }) {
const { text, sameLang, loading } = useTranslate(q, rule, translator.setting);
const { textStyle, bgColor } = rule;
const { newlineLength = TRANS_NEWLINE_LENGTH } = translator.setting;
const handleMouseEnter = () => {
setHover(true);
};
@@ -87,7 +90,7 @@ export default function Content({ q, translator }) {
if (loading) {
return (
<>
{q.length > 40 ? <br /> : " "}
{q.length > newlineLength ? <br /> : " "}
<LoadingIcon />
</>
);
@@ -96,7 +99,7 @@ export default function Content({ q, translator }) {
if (text && !sameLang) {
return (
<>
{q.length > 40 ? <br /> : " "}
{q.length > newlineLength ? <br /> : " "}
<span
style={style}
onMouseEnter={handleMouseEnter}

View File

@@ -9,7 +9,7 @@ import Link from "@mui/material/Link";
import { useSetting } from "../../hooks/Setting";
import { limitNumber } from "../../libs/utils";
import { useI18n } from "../../hooks/I18n";
import { UI_LANGS, URL_KISS_WORKER } from "../../config";
import { UI_LANGS, URL_KISS_WORKER, TRANS_NEWLINE_LENGTH } from "../../config";
export default function Settings() {
const i18n = useI18n();
@@ -31,6 +31,9 @@ export default function Settings() {
case "maxLength":
value = limitNumber(value, 100, 10000);
break;
case "newlineLength":
value = limitNumber(value, 1, 1000);
break;
default:
}
updateSetting({
@@ -50,6 +53,7 @@ export default function Settings() {
openaiModel,
openaiPrompt,
clearCache,
newlineLength = TRANS_NEWLINE_LENGTH,
} = setting;
return (
@@ -107,6 +111,15 @@ export default function Settings() {
onChange={handleChange}
/>
<TextField
size="small"
label={i18n("num_of_newline_characters")}
type="number"
name="newlineLength"
value={newlineLength}
onChange={handleChange}
/>
<FormControl size="small">
<InputLabel>{i18n("clear_cache")}</InputLabel>
<Select