fix: Fixed issue where converting to Super would result in empty note
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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} />
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user