feat(config): Set markdown's font-family

This commit is contained in:
frostime 2024-08-03 16:04:20 +08:00
parent d9e407fd2b
commit b6a022b0ef
6 changed files with 21 additions and 0 deletions

View File

@ -732,6 +732,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);
@ -1482,6 +1483,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}
/> />
@ -1576,6 +1578,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

@ -1316,6 +1316,19 @@ export function Settings() {
></InputRange> ></InputRange>
</ListItem> </ListItem>
<ListItem title="字体" subTitle="设置全局字体">
<input
type="text"
value={config.fontFamily}
placeholder="CSS Font Family"
onChange={(e) =>
updateConfig(
(config) => (config.fontFamily = e.currentTarget.value),
)
}
></input>
</ListItem>
<ListItem <ListItem
title={Locale.Settings.AutoGenerateTitle.Title} title={Locale.Settings.AutoGenerateTitle.Title}
subTitle={Locale.Settings.AutoGenerateTitle.SubTitle} subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}

View File

@ -33,6 +33,7 @@ export const DEFAULT_CONFIG = {
submitKey: SubmitKey.Enter, submitKey: SubmitKey.Enter,
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: true, sendPreviewBubble: true,

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(