这是indexloc提供的服务,不要输入任何密码
Skip to content

Add Disable Spellcheck Option #3795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Pencil } from "@phosphor-icons/react";
import { useState, useEffect, useRef } from "react";
import Appearance from "@/models/appearance";

const EDIT_EVENT = "toggle-message-edit";

Expand Down Expand Up @@ -98,6 +99,7 @@ export function EditMessageForm({
<textarea
ref={formRef}
name="editedMessage"
spellCheck={Appearance.get("enableSpellCheck")}
className="text-white w-full rounded bg-theme-bg-secondary border border-white/20 active:outline-none focus:outline-none focus:ring-0 pr-16 pl-1.5 pt-1.5 resize-y"
defaultValue={message}
onChange={adjustTextArea}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AttachItem from "./AttachItem";
import { PASTE_ATTACHMENT_EVENT } from "../DnDWrapper";
import useTextSize from "@/hooks/useTextSize";
import { useTranslation } from "react-i18next";
import Appearance from "@/models/appearance";

export const PROMPT_INPUT_EVENT = "set_prompt_input";
const MAX_EDIT_STACK_SIZE = 100;
Expand Down Expand Up @@ -268,6 +269,7 @@ export default function PromptInput({
adjustTextArea(e);
}}
value={promptInput}
spellCheck={Appearance.get("enableSpellCheck")}
className={`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow ${textSizeClass}`}
placeholder={t("chat_window.send_message")}
/>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/ar/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/da/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/de/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/en/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ const TRANSLATIONS = {
title: "Auto-Speak Responses",
description: "Automatically speak responses from the AI",
},
spellcheck: {
title: "Enable Spellcheck",
description: "Enable or disable spellcheck in the chat input field",
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/es/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/fa/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/fr/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/he/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/it/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/ja/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/ko/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/nl/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/pt_BR/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/ru/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/tr/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/vn/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ const TRANSLATIONS = {
title: null,
description: null,
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/zh/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ const TRANSLATIONS = {
title: "自动语音回复",
description: "自动朗读 AI 的回复内容",
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/zh_TW/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ const TRANSLATIONS = {
title: "自動語音回應",
description: "自動朗讀 AI 的回應內容",
},
spellcheck: {
title: null,
description: null,
},
},
items: {
theme: {
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/models/appearance.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { APPEARANCE_SETTINGS } from "@/utils/constants";

/**
* @typedef { 'showScrollbar' |
* 'autoSubmitSttInput' |
* 'autoPlayAssistantTtsResponse' |
* 'enableSpellCheck'
* } AvailableSettings - The supported settings for the appearance model.
*/

const Appearance = {
defaultSettings: {
showScrollbar: false,
autoSubmitSttInput: true,
autoPlayAssistantTtsResponse: false,
enableSpellCheck: true,
},

/**
Expand All @@ -22,8 +31,8 @@ const Appearance = {

/**
* Fetches a specific setting from the user's settings
* @param {string} key - The key of the setting to fetch
* @returns {any} - a default value if the setting is not found or the current value
* @param {AvailableSettings} key - The key of the setting to fetch
* @returns {boolean} - a default value if the setting is not found or the current value
*/
get: (key) => {
const settings = Appearance.getSettings();
Expand All @@ -34,7 +43,7 @@ const Appearance = {

/**
* Updates a specific setting from the user's settings
* @param {string} key - The key of the setting to update
* @param {AvailableSettings} key - The key of the setting to update
* @param {any} value - The value to update the setting to
* @returns {object}
*/
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/GeneralSettings/Settings/Chat/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isMobile } from "react-device-detect";
import { useTranslation } from "react-i18next";
import AutoSubmit from "../components/AutoSubmit";
import AutoSpeak from "../components/AutoSpeak";
import SpellCheck from "../components/SpellCheck";

export default function ChatSettings() {
const { t } = useTranslation();
Expand All @@ -27,6 +28,7 @@ export default function ChatSettings() {
</div>
<AutoSubmit />
<AutoSpeak />
<SpellCheck />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState, useEffect } from "react";
import Appearance from "@/models/appearance";
import { useTranslation } from "react-i18next";

export default function SpellCheck() {
const { t } = useTranslation();
const [saving, setSaving] = useState(false);
const [enableSpellCheck, setEnableSpellCheck] = useState(
Appearance.get("enableSpellCheck")
);

const handleChange = async (e) => {
const newValue = e.target.checked;
setEnableSpellCheck(newValue);
setSaving(true);
try {
Appearance.set("enableSpellCheck", newValue);
} catch (error) {
console.error("Failed to update appearance settings:", error);
setEnableSpellCheck(!newValue);
}
setSaving(false);
};

return (
<div className="flex flex-col gap-y-0.5 my-4">
<p className="text-sm leading-6 font-semibold text-white">
{t("customization.chat.spellcheck.title")}
</p>
<p className="text-xs text-white/60">
{t("customization.chat.spellcheck.description")}
</p>
<div className="flex items-center gap-x-4">
<label className="relative inline-flex cursor-pointer items-center">
<input
id="spellcheck"
type="checkbox"
name="spellcheck"
value="yes"
checked={enableSpellCheck}
onChange={handleChange}
disabled={saving}
className="peer sr-only"
/>
<div className="pointer-events-none peer h-6 w-11 rounded-full bg-[#CFCFD0] after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:shadow-xl after:border-none after:bg-white after:box-shadow-md after:transition-all after:content-[''] peer-checked:bg-[#32D583] peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-transparent"></div>
</label>
</div>
</div>
);
}