Skip to content

Commit

Permalink
fix(core): center peek does not display custom fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Dec 24, 2024
1 parent 884bbd2 commit c46bd77
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { BlockSuiteEditor } from '@affine/core/components/blocksuite/block-suite
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
import { PageNotFound } from '@affine/core/desktop/pages/404';
import { EditorService } from '@affine/core/modules/editor';
import {
EditorSettingService,
fontStyleOptions,
} from '@affine/core/modules/editor-setting';
import { DebugLogger } from '@affine/debug';
import {
type EdgelessRootService,
Expand All @@ -19,8 +23,9 @@ import {
useService,
useServices,
} from '@toeverything/infra';
import { cssVar } from '@toeverything/theme';
import clsx from 'clsx';
import { useCallback, useEffect } from 'react';
import { type CSSProperties, useCallback, useEffect, useMemo } from 'react';

import { WorkbenchService } from '../../../workbench';
import type { DocReferenceInfo } from '../../entities/peek-view';
Expand Down Expand Up @@ -85,6 +90,14 @@ function DocPeekPreviewEditor({
const workbench = useService(WorkbenchService).workbench;
const peekView = useService(PeekViewService).peekView;
const editorElement = useLiveData(editor.editorContainer$);
const editorSetting = useService(EditorSettingService).editorSetting;
const settings = useLiveData(
editorSetting.settings$.selector(s => ({
fontFamily: s.fontFamily,
customFontFamily: s.customFontFamily,
fullWidthLayout: s.fullWidthLayout,
}))
);

const handleOnEditorReady = useCallback(
(editorContainer: AffineEditorContainer) => {
Expand Down Expand Up @@ -143,6 +156,20 @@ function DocPeekPreviewEditor({
peekView.close();
}, [doc, peekView, workbench]);

const value = useMemo(() => {
const fontStyle = fontStyleOptions.find(
option => option.key === settings.fontFamily
);
if (!fontStyle) {
return cssVar('fontSansFamily');
}
const customFontFamily = settings.customFontFamily;

return customFontFamily && fontStyle.key === 'Custom'
? `${customFontFamily}, ${fontStyle.value}`
: fontStyle.value;
}, [settings.customFontFamily, settings.fontFamily]);

return (
<AffineErrorBoundary>
<Scrollable.Root>
Expand All @@ -155,6 +182,11 @@ function DocPeekPreviewEditor({
page={doc.blockSuiteDoc}
onEditorReady={handleOnEditorReady}
defaultOpenProperty={defaultOpenProperty}
style={
{
'--affine-font-family': value,
} as CSSProperties
}
/>
</Scrollable.Viewport>
<Scrollable.Scrollbar />
Expand Down

0 comments on commit c46bd77

Please sign in to comment.