Skip to content

Commit c3e3eca

Browse files
committed
2 parents af1088e + 764c0cb commit c3e3eca

File tree

26 files changed

+143
-6
lines changed

26 files changed

+143
-6
lines changed

app/command.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ interface ChatCommands {
4141
del?: Command;
4242
}
4343

44-
export const ChatCommandPrefix = ":";
44+
// Compatible with Chinese colon character ":"
45+
export const ChatCommandPrefix = /^[:]/;
4546

4647
export function useChatCommand(commands: ChatCommands = {}) {
4748
function extract(userInput: string) {
48-
return (
49-
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
50-
) as keyof ChatCommands;
49+
const match = userInput.match(ChatCommandPrefix);
50+
if (match) {
51+
return userInput.slice(1) as keyof ChatCommands;
52+
}
53+
return userInput as keyof ChatCommands;
5154
}
5255

5356
function search(userInput: string) {
@@ -57,7 +60,7 @@ export function useChatCommand(commands: ChatCommands = {}) {
5760
.filter((c) => c.startsWith(input))
5861
.map((c) => ({
5962
title: desc[c as keyof ChatCommands],
60-
content: ChatCommandPrefix + c,
63+
content: ":" + c,
6164
}));
6265
}
6366

app/components/chat.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ function _Chat() {
732732
const session = chatStore.currentSession();
733733
const config = useAppConfig();
734734
const fontSize = config.fontSize;
735+
const fontFamily = config.fontFamily;
735736

736737
const [showExport, setShowExport] = useState(false);
737738

@@ -811,7 +812,7 @@ function _Chat() {
811812
// clear search results
812813
if (n === 0) {
813814
setPromptHints([]);
814-
} else if (text.startsWith(ChatCommandPrefix)) {
815+
} else if (text.match(ChatCommandPrefix)) {
815816
setPromptHints(chatCommands.search(text));
816817
} else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) {
817818
// check if need to trigger auto completion
@@ -1482,6 +1483,7 @@ function _Chat() {
14821483
setUserInput(getMessageTextContent(message));
14831484
}}
14841485
fontSize={fontSize}
1486+
fontFamily={fontFamily}
14851487
parentRef={scrollRef}
14861488
defaultShow={i >= messages.length - 6}
14871489
/>
@@ -1576,6 +1578,7 @@ function _Chat() {
15761578
autoFocus={autoFocus}
15771579
style={{
15781580
fontSize: config.fontSize,
1581+
fontFamily: config.fontFamily,
15791582
}}
15801583
/>
15811584
{attachImages.length != 0 && (

app/components/exporter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ export function ImagePreviewer(props: {
583583
<Markdown
584584
content={getMessageTextContent(m)}
585585
fontSize={config.fontSize}
586+
fontFamily={config.fontFamily}
586587
defaultShow
587588
/>
588589
{getMessageImages(m).length == 1 && (

app/components/markdown.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export function Markdown(
232232
content: string;
233233
loading?: boolean;
234234
fontSize?: number;
235+
fontFamily?: string;
235236
parentRef?: RefObject<HTMLDivElement>;
236237
defaultShow?: boolean;
237238
} & React.DOMAttributes<HTMLDivElement>,
@@ -243,6 +244,7 @@ export function Markdown(
243244
className="markdown-body"
244245
style={{
245246
fontSize: `${props.fontSize ?? 14}px`,
247+
fontFamily: props.fontFamily || "inherit",
246248
}}
247249
ref={mdRef}
248250
onContextMenu={props.onContextMenu}

app/components/settings.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,22 @@ export function Settings() {
13161316
></InputRange>
13171317
</ListItem>
13181318

1319+
<ListItem
1320+
title={Locale.Settings.FontFamily.Title}
1321+
subTitle={Locale.Settings.FontFamily.SubTitle}
1322+
>
1323+
<input
1324+
type="text"
1325+
value={config.fontFamily}
1326+
placeholder={Locale.Settings.FontFamily.Placeholder}
1327+
onChange={(e) =>
1328+
updateConfig(
1329+
(config) => (config.fontFamily = e.currentTarget.value),
1330+
)
1331+
}
1332+
></input>
1333+
</ListItem>
1334+
13191335
<ListItem
13201336
title={Locale.Settings.AutoGenerateTitle.Title}
13211337
subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}

app/locales/ar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ const ar: PartialLocaleType = {
111111
Title: "حجم الخط",
112112
SubTitle: "ضبط حجم الخط لمحتوى الدردشة",
113113
},
114+
FontFamily: {
115+
Title: "خط الدردشة",
116+
SubTitle: "خط محتوى الدردشة، اتركه فارغًا لتطبيق الخط الافتراضي العالمي",
117+
Placeholder: "اسم الخط",
118+
},
114119
InjectSystemPrompts: {
115120
Title: "حقن تلميحات النظام",
116121
SubTitle:

app/locales/bn.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ const bn: PartialLocaleType = {
136136
Title: "ফন্ট সাইজ",
137137
SubTitle: "চ্যাট সামগ্রীর ফন্ট সাইজ সংশোধন করুন",
138138
},
139+
FontFamily: {
140+
Title: "চ্যাট ফন্ট",
141+
SubTitle:
142+
"চ্যাট সামগ্রীর ফন্ট, বিশ্বব্যাপী ডিফল্ট ফন্ট প্রয়োগ করতে খালি রাখুন",
143+
Placeholder: "ফন্টের নাম",
144+
},
139145
InjectSystemPrompts: {
140146
Title: "حقن تلميحات النظام",
141147
SubTitle:

app/locales/cn.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ const cn = {
156156
Title: "字体大小",
157157
SubTitle: "聊天内容的字体大小",
158158
},
159+
FontFamily: {
160+
Title: "聊天字体",
161+
SubTitle: "聊天内容的字体,若置空则应用全局默认字体",
162+
Placeholder: "字体名称",
163+
},
159164
InjectSystemPrompts: {
160165
Title: "注入系统级提示信息",
161166
SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示",

app/locales/cs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const cs: PartialLocaleType = {
7171
Title: "Velikost písma",
7272
SubTitle: "Nastavení velikosti písma obsahu chatu",
7373
},
74+
FontFamily: {
75+
Title: "Chatové Písmo",
76+
SubTitle:
77+
"Písmo obsahu chatu, ponechejte prázdné pro použití globálního výchozího písma",
78+
Placeholder: "Název Písma",
79+
},
7480
InjectSystemPrompts: {
7581
Title: "Vložit systémové prompty",
7682
SubTitle:

app/locales/de.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const de: PartialLocaleType = {
7171
Title: "Schriftgröße",
7272
SubTitle: "Schriftgröße des Chat-Inhalts anpassen",
7373
},
74+
FontFamily: {
75+
Title: "Chat-Schriftart",
76+
SubTitle:
77+
"Schriftart des Chat-Inhalts, leer lassen, um die globale Standardschriftart anzuwenden",
78+
Placeholder: "Schriftartname",
79+
},
7480
InjectSystemPrompts: {
7581
Title: "System-Prompts einfügen",
7682
SubTitle:

0 commit comments

Comments
 (0)