fix: Fixed issue where converting to Super would result in empty note

This commit is contained in:
Aman Harwara
2023-02-01 21:25:12 +05:30
parent 0a72e8f609
commit cf4e34858f
5 changed files with 55 additions and 27 deletions

View File

@@ -3,9 +3,19 @@ import { useEffect } from 'react'
import { $convertFromMarkdownString, TRANSFORMERS } from '@lexical/markdown'
import { $generateNodesFromDOM } from '@lexical/html'
import { $createParagraphNode, $createRangeSelection } from 'lexical'
import { handleEditorChange } from '@standardnotes/blocks-editor/src/Editor/Utils'
import { SuperNotePreviewCharLimit } from '../../SuperEditor'
/** Note that markdown conversion does not insert new lines. See: https://github.com/facebook/lexical/issues/2815 */
export default function ImportPlugin({ text, format }: { text: string; format: 'md' | 'html' }): JSX.Element | null {
export default function ImportPlugin({
text,
format,
onChange,
}: {
text: string
format: 'md' | 'html'
onChange: (value: string, preview: string) => void
}): JSX.Element | null {
const [editor] = useLexicalComposerContext()
useEffect(() => {
@@ -28,5 +38,13 @@ export default function ImportPlugin({ text, format }: { text: string; format: '
})
}, [editor, text, format])
useEffect(() => {
return editor.registerUpdateListener(({ editorState }) => {
editorState.read(() => {
handleEditorChange(editorState, SuperNotePreviewCharLimit, onChange)
})
})
}, [editor, onChange])
return null
}

View File

@@ -44,7 +44,7 @@ import ModalOverlay from '@/Components/Modal/ModalOverlay'
import MobileToolbarPlugin from './Plugins/MobileToolbarPlugin/MobileToolbarPlugin'
import { SuperEditorNodes } from './SuperEditorNodes'
const NotePreviewCharLimit = 160
export const SuperNotePreviewCharLimit = 160
type Props = {
application: WebApplication
@@ -182,7 +182,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
lineHeight && `leading-${lineHeight.toLowerCase()}`,
fontSize ? getPlaintextFontSize(fontSize) : 'text-base',
)}
previewLength={NotePreviewCharLimit}
previewLength={SuperNotePreviewCharLimit}
spellcheck={spellcheck}
>
<ItemSelectionPlugin currentNote={note.current} />

View File

@@ -122,7 +122,7 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
previewLength={NotePreviewCharLimit}
spellcheck={note.spellcheck}
>
<ImportPlugin text={note.text} format={format} />
<ImportPlugin text={note.text} format={format} onChange={handleChange} />
</BlocksEditor>
</BlocksEditorComposer>
</ErrorBoundary>