优化字体

This commit is contained in:
sijinhui 2024-08-03 21:30:32 +08:00
commit 86e8303104
9 changed files with 60 additions and 20 deletions

View File

@ -759,6 +759,7 @@ function _Chat() {
const session = chatStore.currentSession(); const session = chatStore.currentSession();
const config = useAppConfig(); const config = useAppConfig();
const fontSize = config.fontSize; const fontSize = config.fontSize;
const fontFamily = config.fontFamily;
const [showExport, setShowExport] = useState(false); const [showExport, setShowExport] = useState(false);
@ -1544,6 +1545,7 @@ function _Chat() {
// setUserInput(getMessageTextContent(message)); // setUserInput(getMessageTextContent(message));
// }} // }}
fontSize={fontSize} fontSize={fontSize}
fontFamily={fontFamily}
parentRef={scrollRef} parentRef={scrollRef}
defaultShow={i >= messages.length - 6} defaultShow={i >= messages.length - 6}
/> />
@ -1776,6 +1778,7 @@ function _Chat() {
autoFocus={autoFocus} autoFocus={autoFocus}
style={{ style={{
fontSize: config.fontSize, fontSize: config.fontSize,
fontFamily: config.fontFamily,
}} }}
/> />
{attachImages.length != 0 && ( {attachImages.length != 0 && (

View File

@ -583,6 +583,7 @@ export function ImagePreviewer(props: {
<Markdown <Markdown
content={getMessageTextContent(m)} content={getMessageTextContent(m)}
fontSize={config.fontSize} fontSize={config.fontSize}
fontFamily={config.fontFamily}
defaultShow defaultShow
/> />
{getMessageImages(m).length == 1 && ( {getMessageImages(m).length == 1 && (

View File

@ -232,6 +232,7 @@ export function Markdown(
content: string; content: string;
loading?: boolean; loading?: boolean;
fontSize?: number; fontSize?: number;
fontFamily?: string;
parentRef?: RefObject<HTMLDivElement>; parentRef?: RefObject<HTMLDivElement>;
defaultShow?: boolean; defaultShow?: boolean;
} & React.DOMAttributes<HTMLDivElement>, } & React.DOMAttributes<HTMLDivElement>,
@ -243,6 +244,7 @@ export function Markdown(
className="markdown-body" className="markdown-body"
style={{ style={{
fontSize: `${props.fontSize ?? 14}px`, fontSize: `${props.fontSize ?? 14}px`,
fontFamily: props.fontFamily || "inherit",
}} }}
ref={mdRef} ref={mdRef}
onContextMenu={props.onContextMenu} onContextMenu={props.onContextMenu}

View File

@ -71,7 +71,7 @@ import {
} from "../constant"; } from "../constant";
import { Prompt, SearchService, usePromptStore } from "../store/prompt"; import { Prompt, SearchService, usePromptStore } from "../store/prompt";
import { ErrorBoundary } from "./error"; import { ErrorBoundary } from "./error";
// import { InputRange } from "./input-range"; import { InputRange } from "./input-range";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Avatar, AvatarPicker } from "./emoji"; import { Avatar, AvatarPicker } from "./emoji";
import { getClientConfig } from "../config/client"; import { getClientConfig } from "../config/client";
@ -1297,24 +1297,40 @@ export function Settings() {
{/* </Select>*/} {/* </Select>*/}
{/*</ListItem>*/} {/*</ListItem>*/}
{/*<ListItem*/} <ListItem
{/* title={Locale.Settings.FontSize.Title}*/} title={Locale.Settings.FontSize.Title}
{/* subTitle={Locale.Settings.FontSize.SubTitle}*/} subTitle={Locale.Settings.FontSize.SubTitle}
{/*>*/} >
{/* <InputRange*/} <InputRange
{/* title={`${config.fontSize ?? 14}px`}*/} title={`${config.fontSize ?? 14}px`}
{/* value={config.fontSize}*/} value={config.fontSize}
{/* min="12"*/} min="12"
{/* max="40"*/} max="40"
{/* step="1"*/} step="1"
{/* onChange={(e) =>*/} onChange={(e) =>
{/* updateConfig(*/} updateConfig(
{/* (config) =>*/} (config) =>
{/* (config.fontSize = Number.parseInt(e.currentTarget.value)),*/} (config.fontSize = Number.parseInt(e.currentTarget.value)),
{/* )*/} )
{/* }*/} }
{/* ></InputRange>*/} ></InputRange>
{/*</ListItem>*/} </ListItem>
<ListItem
title={Locale.Settings.FontFamily.Title}
subTitle={Locale.Settings.FontFamily.SubTitle}
>
<input
type="text"
value={config.fontFamily}
placeholder={Locale.Settings.FontFamily.Placeholder}
onChange={(e) =>
updateConfig(
(config) => (config.fontFamily = e.currentTarget.value),
)
}
></input>
</ListItem>
{/*<ListItem*/} {/*<ListItem*/}
{/* title={Locale.Settings.AutoGenerateTitle.Title}*/} {/* title={Locale.Settings.AutoGenerateTitle.Title}*/}

View File

@ -112,7 +112,7 @@ const cn = {
if (submitKey === String(SubmitKey.Enter)) { if (submitKey === String(SubmitKey.Enter)) {
inputHints += "Shift + Enter 换行"; inputHints += "Shift + Enter 换行";
} }
return inputHints + "/ 内置提示词"; return inputHints + ": 快捷功能";
}, },
Send: "发送", Send: "发送",
Config: { Config: {
@ -196,6 +196,11 @@ const cn = {
Title: "字体大小", Title: "字体大小",
SubTitle: "聊天内容的字体大小", SubTitle: "聊天内容的字体大小",
}, },
FontFamily: {
Title: "聊天字体",
SubTitle: "聊天内容的字体,若置空则应用全局默认字体",
Placeholder: "字体名称",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "注入系统级提示信息", Title: "注入系统级提示信息",
SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示", SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示",

View File

@ -198,6 +198,12 @@ const en: LocaleType = {
Title: "Font Size", Title: "Font Size",
SubTitle: "Adjust font size of chat content", 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: { InjectSystemPrompts: {
Title: "Inject System Prompts", Title: "Inject System Prompts",
SubTitle: "Inject a global system prompt for every request", SubTitle: "Inject a global system prompt for every request",

View File

@ -153,6 +153,11 @@ const tw = {
Title: "字型大小", Title: "字型大小",
SubTitle: "聊天內容的字型大小", SubTitle: "聊天內容的字型大小",
}, },
FontFamily: {
Title: "聊天字體",
SubTitle: "聊天內容的字體,若置空則應用全局默認字體",
Placeholder: "字體名稱",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "匯入系統提示", Title: "匯入系統提示",
SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示", SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示",

View File

@ -36,6 +36,7 @@ export const DEFAULT_CONFIG = {
// submitKey: isMacOS() ? SubmitKey.MetaEnter : SubmitKey.CtrlEnter, // submitKey: isMacOS() ? SubmitKey.MetaEnter : SubmitKey.CtrlEnter,
avatar: "1f603", avatar: "1f603",
fontSize: 14, fontSize: 14,
fontFamily: "",
theme: Theme.Auto as Theme, theme: Theme.Auto as Theme,
tightBorder: !!config?.isApp, tightBorder: !!config?.isApp,
sendPreviewBubble: false, sendPreviewBubble: false,

View File

@ -194,6 +194,7 @@ export function autoGrowTextArea(dom: HTMLTextAreaElement) {
measureDom.style.width = width + "px"; measureDom.style.width = width + "px";
measureDom.innerText = dom.value !== "" ? dom.value : "1"; measureDom.innerText = dom.value !== "" ? dom.value : "1";
measureDom.style.fontSize = dom.style.fontSize; measureDom.style.fontSize = dom.style.fontSize;
measureDom.style.fontFamily = dom.style.fontFamily;
const endWithEmptyLine = dom.value.endsWith("\n"); const endWithEmptyLine = dom.value.endsWith("\n");
const height = parseFloat(window.getComputedStyle(measureDom).height); const height = parseFloat(window.getComputedStyle(measureDom).height);
const singleLineHeight = parseFloat( const singleLineHeight = parseFloat(