diff --git a/packages/web/src/javascripts/Components/NoteView/PlainEditor/PlainEditor.tsx b/packages/web/src/javascripts/Components/NoteView/PlainEditor/PlainEditor.tsx index 9391906cc..fdbdf32e0 100644 --- a/packages/web/src/javascripts/Components/NoteView/PlainEditor/PlainEditor.tsx +++ b/packages/web/src/javascripts/Components/NoteView/PlainEditor/PlainEditor.tsx @@ -5,7 +5,7 @@ import { log, LoggingDomain } from '@/Logging' import { Disposer } from '@/Types/Disposer' import { EditorEventSource } from '@/Types/EditorEventSource' import { classNames } from '@standardnotes/utils' -import { getPlaintextFontSize } from '@/Utils/getPlaintextFontSize' +import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize' import { ApplicationEvent, EditorFontSize, @@ -38,6 +38,7 @@ export const PlainEditor = forwardRef( const [textareaUnloading, setTextareaUnloading] = useState(false) const [lineHeight, setLineHeight] = useState() const [fontSize, setFontSize] = useState() + const responsiveFontSize = useResponsiveEditorFontSize(fontSize || EditorFontSize.Normal) const previousSpellcheck = usePrevious(spellcheck) const lastEditorFocusEventSource = useRef() @@ -262,7 +263,7 @@ export const PlainEditor = forwardRef( className={classNames( 'editable font-editor flex-grow', lineHeight && `leading-${lineHeight.toLowerCase()}`, - fontSize && getPlaintextFontSize(fontSize), + responsiveFontSize, )} > ) diff --git a/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx b/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx index 596efefef..aab55c64b 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx @@ -39,7 +39,7 @@ import { SUPER_SHOW_MARKDOWN_PREVIEW } from '@standardnotes/ui-services' import { SuperNoteMarkdownPreview } from './SuperNoteMarkdownPreview' import { ExportPlugin } from './Plugins/ExportPlugin/ExportPlugin' import GetMarkdownPlugin, { GetMarkdownPluginInterface } from './Plugins/GetMarkdownPlugin/GetMarkdownPlugin' -import { getPlaintextFontSize } from '@/Utils/getPlaintextFontSize' +import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize' import ReadonlyPlugin from './Plugins/ReadonlyPlugin/ReadonlyPlugin' import { SuperSearchContextProvider } from './Plugins/SearchPlugin/Context' import { SearchPlugin } from './Plugins/SearchPlugin/SearchPlugin' @@ -162,9 +162,10 @@ export const SuperEditor: FunctionComponent = ({ const [lineHeight, setLineHeight] = useState(() => application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]), ) - const [fontSize, setFontSize] = useState(() => + const [fontSize, setFontSize] = useState(() => application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize]), ) + const responsiveFontSize = useResponsiveEditorFontSize(fontSize) const reloadPreferences = useCallback(() => { const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]) @@ -222,7 +223,7 @@ export const SuperEditor: FunctionComponent = ({ className={classNames( 'blocks-editor relative h-full resize-none px-4 py-4 focus:shadow-none focus:outline-none', lineHeight && `leading-${lineHeight.toLowerCase()}`, - fontSize ? getPlaintextFontSize(fontSize) : 'text-base', + responsiveFontSize, )} previewLength={SuperNotePreviewCharLimit} spellcheck={spellcheck} diff --git a/packages/web/src/javascripts/Utils/getPlaintextFontSize.tsx b/packages/web/src/javascripts/Utils/getPlaintextFontSize.tsx index 3955fc61d..402bc10ab 100644 --- a/packages/web/src/javascripts/Utils/getPlaintextFontSize.tsx +++ b/packages/web/src/javascripts/Utils/getPlaintextFontSize.tsx @@ -1,7 +1,7 @@ -import { isMobileScreen, isTabletScreen } from '@/Utils' +import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' import { EditorFontSize } from '@standardnotes/snjs' -export const getPlaintextFontSize = (key: EditorFontSize): string => { +export const useResponsiveEditorFontSize = (key: EditorFontSize): string => { const desktopMapping: Record = { ExtraSmall: 'text-xs', Small: 'text-sm', @@ -26,9 +26,12 @@ export const getPlaintextFontSize = (key: EditorFontSize): string => { Large: 'text-2xl', } - if (isTabletScreen()) { + const isTabletScreen = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.md) + const isMobileScreen = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.sm) + + if (isTabletScreen) { return tabletMapping[key] } - return isMobileScreen() ? mobileMapping[key] : desktopMapping[key] + return isMobileScreen ? mobileMapping[key] : desktopMapping[key] }