fix: Make super note styling consistent with plaintext notes (#2068)

This commit is contained in:
Aman Harwara
2022-11-29 21:57:23 +05:30
committed by GitHub
parent 02eb969e07
commit a417e5ba8d
2 changed files with 20 additions and 10 deletions

View File

@@ -24,7 +24,6 @@ import FloatingLinkEditorPlugin from '../Lexical/Plugins/FloatingLinkEditorPlugi
import {truncateString} from './Utils'; import {truncateString} from './Utils';
import {SuperEditorContentId} from './Constants'; import {SuperEditorContentId} from './Constants';
import {classNames} from '@standardnotes/utils'; import {classNames} from '@standardnotes/utils';
import {EditorLineHeight} from '@standardnotes/snjs';
import {MarkdownTransformers} from './MarkdownTransformers'; import {MarkdownTransformers} from './MarkdownTransformers';
type BlocksEditorProps = { type BlocksEditorProps = {
@@ -34,7 +33,6 @@ type BlocksEditorProps = {
previewLength?: number; previewLength?: number;
spellcheck?: boolean; spellcheck?: boolean;
ignoreFirstChange?: boolean; ignoreFirstChange?: boolean;
lineHeight?: EditorLineHeight;
readonly?: boolean; readonly?: boolean;
}; };
@@ -45,7 +43,6 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
previewLength, previewLength,
spellcheck, spellcheck,
ignoreFirstChange = false, ignoreFirstChange = false,
lineHeight,
readonly, readonly,
}) => { }) => {
const [didIgnoreFirstChange, setDidIgnoreFirstChange] = useState(false); const [didIgnoreFirstChange, setDidIgnoreFirstChange] = useState(false);
@@ -103,7 +100,6 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
id={SuperEditorContentId} id={SuperEditorContentId}
className={classNames( className={classNames(
'ContentEditable__root overflow-y-auto', 'ContentEditable__root overflow-y-auto',
lineHeight && `leading-${lineHeight.toLowerCase()}`,
className, className,
)} )}
spellCheck={spellcheck} spellCheck={spellcheck}

View File

@@ -1,5 +1,12 @@
import { WebApplication } from '@/Application/Application' import { WebApplication } from '@/Application/Application'
import { ApplicationEvent, EditorLineHeight, isPayloadSourceRetrieved, PrefKey } from '@standardnotes/snjs' import {
ApplicationEvent,
classNames,
EditorFontSize,
EditorLineHeight,
isPayloadSourceRetrieved,
PrefKey,
} from '@standardnotes/snjs'
import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import { BlocksEditor, BlocksEditorComposer } from '@standardnotes/blocks-editor' import { BlocksEditor, BlocksEditorComposer } from '@standardnotes/blocks-editor'
import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin' import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin'
@@ -29,6 +36,7 @@ import { SuperNoteMarkdownPreview } from './SuperNoteMarkdownPreview'
import { ExportPlugin } from './Plugins/ExportPlugin/ExportPlugin' import { ExportPlugin } from './Plugins/ExportPlugin/ExportPlugin'
import GetMarkdownPlugin, { GetMarkdownPluginInterface } from './Plugins/GetMarkdownPlugin/GetMarkdownPlugin' import GetMarkdownPlugin, { GetMarkdownPluginInterface } from './Plugins/GetMarkdownPlugin/GetMarkdownPlugin'
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin' import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin'
import { getPlaintextFontSize } from '@/Utils/getPlaintextFontSize'
const NotePreviewCharLimit = 160 const NotePreviewCharLimit = 160
@@ -81,8 +89,6 @@ export const SuperEditor: FunctionComponent<Props> = ({
}) })
}, [application]) }, [application])
const [lineHeight, setLineHeight] = useState<EditorLineHeight>(PrefDefaults[PrefKey.EditorLineHeight])
const handleChange = useCallback( const handleChange = useCallback(
async (value: string, preview: string) => { async (value: string, preview: string) => {
if (ignoreNextChange.current === true) { if (ignoreNextChange.current === true) {
@@ -129,10 +135,15 @@ export const SuperEditor: FunctionComponent<Props> = ({
return disposer return disposer
}, [controller, controller.item.uuid]) }, [controller, controller.item.uuid])
const [lineHeight, setLineHeight] = useState<EditorLineHeight>(PrefDefaults[PrefKey.EditorLineHeight])
const [fontSize, setFontSize] = useState<EditorFontSize | undefined>()
const reloadPreferences = useCallback(() => { const reloadPreferences = useCallback(() => {
const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]) const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight])
const fontSize = application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize])
setLineHeight(lineHeight) setLineHeight(lineHeight)
setFontSize(fontSize)
}, [application]) }, [application])
useEffect(() => { useEffect(() => {
@@ -144,7 +155,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
}, [reloadPreferences, application]) }, [reloadPreferences, application])
return ( return (
<div className="relative h-full w-full"> <div className="font-editor relative h-full w-full">
<ErrorBoundary> <ErrorBoundary>
<> <>
<LinkingControllerProvider controller={linkingController}> <LinkingControllerProvider controller={linkingController}>
@@ -157,10 +168,13 @@ export const SuperEditor: FunctionComponent<Props> = ({
<BlocksEditor <BlocksEditor
onChange={handleChange} onChange={handleChange}
ignoreFirstChange={true} ignoreFirstChange={true}
className="relative h-full resize-none px-6 py-4 text-base focus:shadow-none focus:outline-none" className={classNames(
'relative h-full resize-none px-4 py-4 focus:shadow-none focus:outline-none',
lineHeight && `leading-${lineHeight.toLowerCase()}`,
fontSize ? getPlaintextFontSize(fontSize) : 'text-base',
)}
previewLength={NotePreviewCharLimit} previewLength={NotePreviewCharLimit}
spellcheck={spellcheck} spellcheck={spellcheck}
lineHeight={lineHeight}
> >
<ItemSelectionPlugin currentNote={note.current} /> <ItemSelectionPlugin currentNote={note.current} />
<FilePlugin /> <FilePlugin />