From deb140de739ccda009fc93ffce1e33e53682b042 Mon Sep 17 00:00:00 2001 From: frostime Date: Fri, 2 Aug 2024 22:27:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=B8=BA=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=89=8D=E7=BC=80=EF=BC=88=20`:`=20=EF=BC=89=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=AD=E6=96=87=E7=AC=A6=E5=8F=B7=20`=EF=BC=9A`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command.ts | 13 ++++++++----- app/components/chat.tsx | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/command.ts b/app/command.ts index e515e5f0bb4..bea4e06f381 100644 --- a/app/command.ts +++ b/app/command.ts @@ -41,13 +41,16 @@ interface ChatCommands { del?: Command; } -export const ChatCommandPrefix = ":"; +// Compatible with Chinese colon character ":" +export const ChatCommandPrefix = /^[::]/; export function useChatCommand(commands: ChatCommands = {}) { function extract(userInput: string) { - return ( - userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput - ) as keyof ChatCommands; + const match = userInput.match(ChatCommandPrefix); + if (match) { + return userInput.slice(1) as keyof ChatCommands; + } + return userInput as keyof ChatCommands; } function search(userInput: string) { @@ -57,7 +60,7 @@ export function useChatCommand(commands: ChatCommands = {}) { .filter((c) => c.startsWith(input)) .map((c) => ({ title: desc[c as keyof ChatCommands], - content: ChatCommandPrefix + c, + content: ":" + c, })); } diff --git a/app/components/chat.tsx b/app/components/chat.tsx index bb4b611ad79..785b1f7cd9c 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -811,7 +811,7 @@ function _Chat() { // clear search results if (n === 0) { setPromptHints([]); - } else if (text.startsWith(ChatCommandPrefix)) { + } else if (text.match(ChatCommandPrefix)) { setPromptHints(chatCommands.search(text)); } else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) { // check if need to trigger auto completion From b6a022b0ef9dc7242b572089f3a1c8a08215bfd1 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 3 Aug 2024 16:04:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20feat(config):=20Set=20markdown'?= =?UTF-8?q?s=20font-family?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat.tsx | 3 +++ app/components/exporter.tsx | 1 + app/components/markdown.tsx | 2 ++ app/components/settings.tsx | 13 +++++++++++++ app/store/config.ts | 1 + app/utils.ts | 1 + 6 files changed, 21 insertions(+) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 785b1f7cd9c..ade30967584 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -732,6 +732,7 @@ function _Chat() { const session = chatStore.currentSession(); const config = useAppConfig(); const fontSize = config.fontSize; + const fontFamily = config.fontFamily; const [showExport, setShowExport] = useState(false); @@ -1482,6 +1483,7 @@ function _Chat() { setUserInput(getMessageTextContent(message)); }} fontSize={fontSize} + fontFamily={fontFamily} parentRef={scrollRef} defaultShow={i >= messages.length - 6} /> @@ -1576,6 +1578,7 @@ function _Chat() { autoFocus={autoFocus} style={{ fontSize: config.fontSize, + fontFamily: config.fontFamily, }} /> {attachImages.length != 0 && ( diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 8210f61fb8f..1771cc9b013 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -583,6 +583,7 @@ export function ImagePreviewer(props: { {getMessageImages(m).length == 1 && ( diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index c12daed6468..1531d2ff0e0 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -232,6 +232,7 @@ export function Markdown( content: string; loading?: boolean; fontSize?: number; + fontFamily?: string; parentRef?: RefObject; defaultShow?: boolean; } & React.DOMAttributes, @@ -243,6 +244,7 @@ export function Markdown( className="markdown-body" style={{ fontSize: `${props.fontSize ?? 14}px`, + fontFamily: props.fontFamily || "inherit", }} ref={mdRef} onContextMenu={props.onContextMenu} diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 3197812259e..f3e3e1c6723 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1316,6 +1316,19 @@ export function Settings() { > + + + updateConfig( + (config) => (config.fontFamily = e.currentTarget.value), + ) + } + > + + Date: Sat, 3 Aug 2024 16:24:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20i18n:=20add=20locale=20about?= =?UTF-8?q?=20"font=20family=20config"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: The language is translated by GPT --- app/components/settings.tsx | 7 +++++-- app/locales/ar.ts | 5 +++++ app/locales/bn.ts | 6 ++++++ app/locales/cn.ts | 5 +++++ app/locales/cs.ts | 6 ++++++ app/locales/de.ts | 6 ++++++ app/locales/en.ts | 6 ++++++ app/locales/es.ts | 6 ++++++ app/locales/fr.ts | 6 ++++++ app/locales/id.ts | 10 ++++++++-- app/locales/it.ts | 6 ++++++ app/locales/jp.ts | 6 ++++++ app/locales/ko.ts | 5 +++++ app/locales/no.ts | 6 ++++++ app/locales/pt.ts | 6 ++++++ app/locales/ru.ts | 6 ++++++ app/locales/sk.ts | 6 ++++++ app/locales/tr.ts | 6 ++++++ app/locales/tw.ts | 5 +++++ app/locales/vi.ts | 6 ++++++ 20 files changed, 117 insertions(+), 4 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index f3e3e1c6723..93976ac4551 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1316,11 +1316,14 @@ export function Settings() { > - + updateConfig( (config) => (config.fontFamily = e.currentTarget.value), diff --git a/app/locales/ar.ts b/app/locales/ar.ts index b58c3a2e8e5..0a35ba603f8 100644 --- a/app/locales/ar.ts +++ b/app/locales/ar.ts @@ -111,6 +111,11 @@ const ar: PartialLocaleType = { Title: "حجم الخط", SubTitle: "ضبط حجم الخط لمحتوى الدردشة", }, + FontFamily: { + Title: "خط الدردشة", + SubTitle: "خط محتوى الدردشة، اتركه فارغًا لتطبيق الخط الافتراضي العالمي", + Placeholder: "اسم الخط", + }, InjectSystemPrompts: { Title: "حقن تلميحات النظام", SubTitle: diff --git a/app/locales/bn.ts b/app/locales/bn.ts index 6dfb0da9bc4..cc650a3fe99 100644 --- a/app/locales/bn.ts +++ b/app/locales/bn.ts @@ -136,6 +136,12 @@ const bn: PartialLocaleType = { Title: "ফন্ট সাইজ", SubTitle: "চ্যাট সামগ্রীর ফন্ট সাইজ সংশোধন করুন", }, + FontFamily: { + Title: "চ্যাট ফন্ট", + SubTitle: + "চ্যাট সামগ্রীর ফন্ট, বিশ্বব্যাপী ডিফল্ট ফন্ট প্রয়োগ করতে খালি রাখুন", + Placeholder: "ফন্টের নাম", + }, InjectSystemPrompts: { Title: "حقن تلميحات النظام", SubTitle: diff --git a/app/locales/cn.ts b/app/locales/cn.ts index dea7232fcd4..69ada8784a0 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -156,6 +156,11 @@ const cn = { Title: "字体大小", SubTitle: "聊天内容的字体大小", }, + FontFamily: { + Title: "聊天字体", + SubTitle: "聊天内容的字体,若置空则应用全局默认字体", + Placeholder: "字体名称", + }, InjectSystemPrompts: { Title: "注入系统级提示信息", SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示", diff --git a/app/locales/cs.ts b/app/locales/cs.ts index c1a84430fb3..e70a0e839d7 100644 --- a/app/locales/cs.ts +++ b/app/locales/cs.ts @@ -71,6 +71,12 @@ const cs: PartialLocaleType = { Title: "Velikost písma", SubTitle: "Nastavení velikosti písma obsahu chatu", }, + FontFamily: { + Title: "Chatové Písmo", + SubTitle: + "Písmo obsahu chatu, ponechejte prázdné pro použití globálního výchozího písma", + Placeholder: "Název Písma", + }, InjectSystemPrompts: { Title: "Vložit systémové prompty", SubTitle: diff --git a/app/locales/de.ts b/app/locales/de.ts index 2fe871bc9f0..e50760d88f6 100644 --- a/app/locales/de.ts +++ b/app/locales/de.ts @@ -71,6 +71,12 @@ const de: PartialLocaleType = { Title: "Schriftgröße", SubTitle: "Schriftgröße des Chat-Inhalts anpassen", }, + FontFamily: { + Title: "Chat-Schriftart", + SubTitle: + "Schriftart des Chat-Inhalts, leer lassen, um die globale Standardschriftart anzuwenden", + Placeholder: "Schriftartname", + }, InjectSystemPrompts: { Title: "System-Prompts einfügen", SubTitle: diff --git a/app/locales/en.ts b/app/locales/en.ts index d036ffce010..9a7410cbe0b 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -158,6 +158,12 @@ const en: LocaleType = { Title: "Font Size", SubTitle: "Adjust font size of chat content", }, + FontFamily: { + Title: "Chat Font Family", + SubTitle: + "Font Family of the chat content, leave empty to apply global default font", + Placeholder: "Font Family Name", + }, InjectSystemPrompts: { Title: "Inject System Prompts", SubTitle: "Inject a global system prompt for every request", diff --git a/app/locales/es.ts b/app/locales/es.ts index 7d742d536e5..f595fa3fc4c 100644 --- a/app/locales/es.ts +++ b/app/locales/es.ts @@ -71,6 +71,12 @@ const es: PartialLocaleType = { Title: "Tamaño de fuente", SubTitle: "Ajustar el tamaño de fuente del contenido del chat", }, + FontFamily: { + Title: "Fuente del Chat", + SubTitle: + "Fuente del contenido del chat, dejar vacío para aplicar la fuente predeterminada global", + Placeholder: "Nombre de la Fuente", + }, InjectSystemPrompts: { Title: "Inyectar Prompts del Sistema", SubTitle: diff --git a/app/locales/fr.ts b/app/locales/fr.ts index 944754d62a7..0fac154ed8e 100644 --- a/app/locales/fr.ts +++ b/app/locales/fr.ts @@ -111,6 +111,12 @@ const fr: PartialLocaleType = { Title: "Taille des polices", SubTitle: "Ajuste la taille de police du contenu de la conversation", }, + FontFamily: { + Title: "Police de Chat", + SubTitle: + "Police du contenu du chat, laissez vide pour appliquer la police par défaut globale", + Placeholder: "Nom de la Police", + }, InjectSystemPrompts: { Title: "Injecter des invites système", SubTitle: diff --git a/app/locales/id.ts b/app/locales/id.ts index 571156a5776..0353433f9c7 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -140,6 +140,12 @@ const id: PartialLocaleType = { Title: "Ukuran Font", SubTitle: "Ubah ukuran font konten chat", }, + FontFamily: { + Title: "Font Obrolan", + SubTitle: + "Font dari konten obrolan, biarkan kosong untuk menerapkan font default global", + Placeholder: "Nama Font", + }, InjectSystemPrompts: { Title: "Suntikkan Petunjuk Sistem", SubTitle: @@ -369,8 +375,8 @@ const id: PartialLocaleType = { }, Exporter: { Description: { - Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan" - }, + Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan", + }, Model: "Model", Messages: "Pesan", Topic: "Topik", diff --git a/app/locales/it.ts b/app/locales/it.ts index 7f0a95846c2..5981c8d3db3 100644 --- a/app/locales/it.ts +++ b/app/locales/it.ts @@ -71,6 +71,12 @@ const it: PartialLocaleType = { Title: "Dimensione carattere", SubTitle: "Regolare la dimensione dei caratteri del contenuto della chat", }, + FontFamily: { + Title: "Font della Chat", + SubTitle: + "Carattere del contenuto della chat, lascia vuoto per applicare il carattere predefinito globale", + Placeholder: "Nome del Font", + }, InjectSystemPrompts: { Title: "Inserisci Prompts di Sistema", SubTitle: diff --git a/app/locales/jp.ts b/app/locales/jp.ts index dcbd0f2821b..94ed8f8acdc 100644 --- a/app/locales/jp.ts +++ b/app/locales/jp.ts @@ -118,6 +118,12 @@ const jp: PartialLocaleType = { Title: "フォントサイズ", SubTitle: "チャット内容のフォントサイズ", }, + FontFamily: { + Title: "チャットフォント", + SubTitle: + "チャットコンテンツのフォント、空白の場合はグローバルデフォルトフォントを適用します", + Placeholder: "フォント名", + }, InjectSystemPrompts: { Title: "システムプロンプトの挿入", SubTitle: diff --git a/app/locales/ko.ts b/app/locales/ko.ts index 844459fc4ea..b392e1c77bb 100644 --- a/app/locales/ko.ts +++ b/app/locales/ko.ts @@ -72,6 +72,11 @@ const ko: PartialLocaleType = { Title: "글꼴 크기", SubTitle: "채팅 내용의 글꼴 크기 조정", }, + FontFamily: { + Title: "채팅 폰트", + SubTitle: "채팅 내용의 폰트, 비워 두면 글로벌 기본 폰트를 적용", + Placeholder: "폰트 이름", + }, InjectSystemPrompts: { Title: "시스템 프롬프트 주입", SubTitle: diff --git a/app/locales/no.ts b/app/locales/no.ts index 3a0e61107a4..5e9dc252d72 100644 --- a/app/locales/no.ts +++ b/app/locales/no.ts @@ -66,6 +66,12 @@ const no: PartialLocaleType = { Title: "Fontstørrelsen", SubTitle: "Juster fontstørrelsen for samtaleinnholdet.", }, + FontFamily: { + Title: "Chat-skrifttype", + SubTitle: + "Skrifttypen for chatinnhold, la stå tom for å bruke global standardskrifttype", + Placeholder: "Skriftnavn", + }, InjectSystemPrompts: { Title: "Sett inn systemprompter", SubTitle: diff --git a/app/locales/pt.ts b/app/locales/pt.ts index 8151b7aa4ac..10e915e9254 100644 --- a/app/locales/pt.ts +++ b/app/locales/pt.ts @@ -153,6 +153,12 @@ const pt: PartialLocaleType = { Title: "Tamanho da Fonte", SubTitle: "Ajustar o tamanho da fonte do conteúdo do chat", }, + FontFamily: { + Title: "Fonte do Chat", + SubTitle: + "Fonte do conteúdo do chat, deixe vazio para aplicar a fonte padrão global", + Placeholder: "Nome da Fonte", + }, InjectSystemPrompts: { Title: "Inserir Prompts de Sistema", SubTitle: "Inserir um prompt de sistema global para cada requisição", diff --git a/app/locales/ru.ts b/app/locales/ru.ts index d12cf3e4258..b547402eae0 100644 --- a/app/locales/ru.ts +++ b/app/locales/ru.ts @@ -71,6 +71,12 @@ const ru: PartialLocaleType = { Title: "Размер шрифта", SubTitle: "Настроить размер шрифта контента чата", }, + FontFamily: { + Title: "Шрифт чата", + SubTitle: + "Шрифт содержимого чата, оставьте пустым для применения глобального шрифта по умолчанию", + Placeholder: "Название шрифта", + }, InjectSystemPrompts: { Title: "Вставить системные подсказки", SubTitle: diff --git a/app/locales/sk.ts b/app/locales/sk.ts index a97b7175c24..9014f4f0c85 100644 --- a/app/locales/sk.ts +++ b/app/locales/sk.ts @@ -155,6 +155,12 @@ const sk: PartialLocaleType = { Title: "Veľkosť písma", SubTitle: "Nastaviť veľkosť písma obsahu chatu", }, + FontFamily: { + Title: "Chatové Písmo", + SubTitle: + "Písmo obsahu chatu, ponechajte prázdne pre použitie globálneho predvoleného písma", + Placeholder: "Názov Písma", + }, InjectSystemPrompts: { Title: "Vložiť systémové výzvy", SubTitle: "Vložiť globálnu systémovú výzvu pre každú požiadavku", diff --git a/app/locales/tr.ts b/app/locales/tr.ts index 524c1b2c546..551e5e342c6 100644 --- a/app/locales/tr.ts +++ b/app/locales/tr.ts @@ -71,6 +71,12 @@ const tr: PartialLocaleType = { Title: "Yazı Boyutu", SubTitle: "Sohbet içeriğinin yazı boyutunu ayarlayın", }, + FontFamily: { + Title: "Sohbet Yazı Tipi", + SubTitle: + "Sohbet içeriğinin yazı tipi, boş bırakıldığında küresel varsayılan yazı tipi uygulanır", + Placeholder: "Yazı Tipi Adı", + }, InjectSystemPrompts: { Title: "Sistem İpucu Ekleyin", SubTitle: diff --git a/app/locales/tw.ts b/app/locales/tw.ts index 8011de13f74..03afd432c85 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -153,6 +153,11 @@ const tw = { Title: "字型大小", SubTitle: "聊天內容的字型大小", }, + FontFamily: { + Title: "聊天字體", + SubTitle: "聊天內容的字體,若置空則應用全局默認字體", + Placeholder: "字體名稱", + }, InjectSystemPrompts: { Title: "匯入系統提示", SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示", diff --git a/app/locales/vi.ts b/app/locales/vi.ts index 3d95b566497..1f5c4fc685b 100644 --- a/app/locales/vi.ts +++ b/app/locales/vi.ts @@ -71,6 +71,12 @@ const vi: PartialLocaleType = { Title: "Font chữ", SubTitle: "Thay đổi font chữ của nội dung trò chuyện", }, + FontFamily: { + Title: "Phông Chữ Trò Chuyện", + SubTitle: + "Phông chữ của nội dung trò chuyện, để trống để áp dụng phông chữ mặc định toàn cầu", + Placeholder: "Tên Phông Chữ", + }, InjectSystemPrompts: { Title: "Tiêm Prompt Hệ thống", SubTitle: