fix: font style setting only control editor's font (#3117)

Co-authored-by: Alex Yang <himself65@outlook.com>
(cherry picked from commit cfa18d1bc3)
This commit is contained in:
Qi
2023-07-10 19:58:53 +08:00
committed by Alex Yang
parent 1effd9b22e
commit 38521dc8b2
4 changed files with 43 additions and 35 deletions
@@ -58,14 +58,7 @@ const FontFamilySettings = () => {
defaultValue={appSettings.fontStyle}
onValueChange={useCallback(
(key: AppSetting['fontStyle']) => {
const value = fontStyleOptions.find(option => option.key === key)
?.value;
setAppSettings({ fontStyle: key });
document
.querySelector('html')
?.style.setProperty('--affine-font-family', value || null);
},
[setAppSettings]
)}
+16 -4
View File
@@ -21,13 +21,13 @@ import type { PluginBlockSuiteAdapter } from '@toeverything/plugin-infra/type';
import clsx from 'clsx';
import { useAtomValue, useSetAtom } from 'jotai';
import Head from 'next/head';
import type { FC, ReactElement } from 'react';
import React, { memo, Suspense, useCallback, useMemo } from 'react';
import type { CSSProperties, FC, ReactElement } from 'react';
import { memo, Suspense, useCallback, useMemo } from 'react';
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
import { pageSettingFamily } from '../atoms';
import { contentLayoutAtom } from '../atoms/layout';
import { useAppSetting } from '../atoms/settings';
import { fontStyleOptions, useAppSetting } from '../atoms/settings';
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
import { editor } from './page-detail-editor.css';
import { pluginContainer } from './page-detail-editor.css';
@@ -69,12 +69,24 @@ const EditorWrapper = memo(function EditorWrapper({
const [appSettings] = useAppSetting();
assertExists(meta);
const value = useMemo(() => {
const fontStyle = fontStyleOptions.find(
option => option.key === appSettings.fontStyle
);
assertExists(fontStyle);
return fontStyle.value;
}, [appSettings.fontStyle]);
return (
<Editor
className={clsx(editor, {
'full-screen': appSettings?.fullWidthLayout,
'full-screen': appSettings.fullWidthLayout,
})}
style={
{
'--affine-font-family': value,
} as CSSProperties
}
key={`${workspace.id}-${pageId}`}
mode={isPublic ? 'page' : currentMode}
page={page}