@@ -893,7 +893,7 @@ export const corePlugin = realmPlugin<{
893
893
translation : Translation
894
894
trim ?: boolean
895
895
lexicalTheme ?: EditorThemeClasses
896
- editorState ?: EditorState | undefined
896
+ editorState ?: EditorState | null | undefined
897
897
suppressSharedHistory ?: boolean
898
898
} > ( {
899
899
init ( r , params ) {
@@ -951,7 +951,7 @@ export const corePlugin = realmPlugin<{
951
951
952
952
postInit ( r , params ) {
953
953
const newEditor = createEditor ( {
954
- ...( params ?. editorState ? { editorState : params . editorState } : { } ) ,
954
+ // ...(params?.editorState ? { editorState: params.editorState } : {}),
955
955
editable : params ?. readOnly !== true ,
956
956
namespace : 'MDXEditor' ,
957
957
nodes : r . getValue ( usedLexicalNodes$ ) ,
@@ -961,26 +961,28 @@ export const corePlugin = realmPlugin<{
961
961
theme : r . getValue ( lexicalTheme$ )
962
962
} )
963
963
964
- newEditor . update ( ( ) => {
965
- const markdown = params ?. initialMarkdown . trim ( ) ?? ''
966
- tryImportingMarkdown ( r , $getRoot ( ) , markdown )
964
+ if ( params ?. editorState !== null ) {
965
+ newEditor . update ( ( ) => {
966
+ const markdown = params ?. initialMarkdown . trim ( ) ?? ''
967
+ tryImportingMarkdown ( r , $getRoot ( ) , markdown )
967
968
968
- const autoFocusValue = params ?. autoFocus
969
- if ( autoFocusValue ) {
970
- if ( autoFocusValue === true ) {
971
- // Default 'on' state
969
+ const autoFocusValue = params ?. autoFocus
970
+ if ( autoFocusValue ) {
971
+ if ( autoFocusValue === true ) {
972
+ // Default 'on' state
973
+ setTimeout ( ( ) => {
974
+ newEditor . focus ( noop , { defaultSelection : 'rootStart' } )
975
+ } )
976
+ return
977
+ }
972
978
setTimeout ( ( ) => {
973
- newEditor . focus ( noop , { defaultSelection : 'rootStart' } )
979
+ newEditor . focus ( noop , {
980
+ defaultSelection : autoFocusValue . defaultSelection ?? 'rootStart'
981
+ } )
974
982
} )
975
- return
976
983
}
977
- setTimeout ( ( ) => {
978
- newEditor . focus ( noop , {
979
- defaultSelection : autoFocusValue . defaultSelection ?? 'rootStart'
980
- } )
981
- } )
982
- }
983
- } )
984
+ } )
985
+ }
984
986
985
987
r . pub ( rootEditor$ , newEditor )
986
988
r . pub ( activeEditor$ , newEditor )
0 commit comments