@@ -159,9 +159,9 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
159159 window . removeEventListener ( 'resize' , this . resizeEditor ) ;
160160 // Make sure that everything has run before disposing, to prevent any inconsistensies
161161
162- if ( this . editor ) {
163- this . editor . dispose ( ) ;
164- }
162+ // if (this.editor) {
163+ // this.editor.dispose();
164+ // }
165165 if ( this . lintWorker ) {
166166 this . lintWorker . terminate ( ) ;
167167 }
@@ -638,22 +638,14 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
638638 dependencies : $PropertyType < Props , 'dependencies' >
639639 ) : Promise < null > =>
640640 new Promise ( resolve => {
641- const oldSandbox = this . sandbox ;
642-
643641 this . sandbox = newSandbox ;
644642 this . currentModule = newCurrentModule ;
645643 this . dependencies = dependencies ;
646644
647- // Reset models, dispose old ones
648- this . disposeModules ( oldSandbox . modules ) ;
649-
650645 // Do in setTimeout, since disposeModules is async
651646 setTimeout ( ( ) => {
652647 this . getConfigSchemas ( ) ;
653- // Initialize new models
654- this . initializeModules ( newSandbox . modules )
655- . then ( ( ) => this . openNewModel ( newCurrentModule ) )
656- . then ( resolve ) ;
648+ resolve ( null ) ;
657649 } ) ;
658650 } ) ;
659651
@@ -775,76 +767,83 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
775767 } ;
776768
777769 setErrors = ( errors : Array < ModuleError > ) => {
778- if ( errors . length > 0 ) {
779- const thisModuleErrors = errors . filter (
780- error => error . moduleId === this . currentModule . id
781- ) ;
782- const errorMarkers = thisModuleErrors
783- . map ( error => {
784- if ( error ) {
785- return {
786- severity : this . monaco . Severity . Error ,
787- startColumn : 1 ,
788- startLineNumber : error . line ,
789- endColumn : error . column ,
790- endLineNumber : error . line + 1 ,
791- message : error . message ,
792- } ;
793- }
770+ const activeEditor = this . editor . getActiveCodeEditor ( ) ;
794771
795- return null ;
796- } )
797- . filter ( x => x ) ;
772+ if ( activeEditor ) {
773+ if ( errors . length > 0 ) {
774+ const thisModuleErrors = errors . filter (
775+ error => error . moduleId === this . currentModule . id
776+ ) ;
777+ const errorMarkers = thisModuleErrors
778+ . map ( error => {
779+ if ( error ) {
780+ return {
781+ severity : this . monaco . Severity . Error ,
782+ startColumn : 1 ,
783+ startLineNumber : error . line ,
784+ endColumn : error . column ,
785+ endLineNumber : error . line + 1 ,
786+ message : error . message ,
787+ } ;
788+ }
798789
799- this . monaco . editor . setModelMarkers (
800- this . editor . getActiveCodeEditor ( ) . getModel ( ) ,
801- 'error' ,
802- errorMarkers
803- ) ;
804- } else {
805- this . monaco . editor . setModelMarkers (
806- this . editor . getActiveCodeEditor ( ) . getModel ( ) ,
807- 'error' ,
808- [ ]
809- ) ;
790+ return null ;
791+ } )
792+ . filter ( x => x ) ;
793+
794+ this . monaco . editor . setModelMarkers (
795+ activeEditor . getModel ( ) ,
796+ 'error' ,
797+ errorMarkers
798+ ) ;
799+ } else {
800+ this . monaco . editor . setModelMarkers (
801+ activeEditor . getModel ( ) ,
802+ 'error' ,
803+ [ ]
804+ ) ;
805+ }
810806 }
811807 } ;
812808
813809 setCorrections = ( corrections : Array < ModuleCorrection > ) => {
814- if ( corrections . length > 0 ) {
815- const correctionMarkers = corrections
816- . filter ( correction => correction . moduleId === this . currentModule . id )
817- . map ( correction => {
818- if ( correction ) {
819- return {
820- severity :
821- correction . severity === 'warning'
822- ? this . monaco . Severity . Warning
823- : this . monaco . Severity . Notice ,
824- startColumn : correction . column ,
825- startLineNumber : correction . line ,
826- endColumn : 1 ,
827- endLineNumber : correction . line + 1 ,
828- message : correction . message ,
829- source : correction . source ,
830- } ;
831- }
810+ const activeEditor = this . editor . getActiveCodeEditor ( ) ;
811+ if ( activeEditor ) {
812+ if ( corrections . length > 0 ) {
813+ const correctionMarkers = corrections
814+ . filter ( correction => correction . moduleId === this . currentModule . id )
815+ . map ( correction => {
816+ if ( correction ) {
817+ return {
818+ severity :
819+ correction . severity === 'warning'
820+ ? this . monaco . Severity . Warning
821+ : this . monaco . Severity . Notice ,
822+ startColumn : correction . column ,
823+ startLineNumber : correction . line ,
824+ endColumn : 1 ,
825+ endLineNumber : correction . line + 1 ,
826+ message : correction . message ,
827+ source : correction . source ,
828+ } ;
829+ }
832830
833- return null ;
834- } )
835- . filter ( x => x ) ;
831+ return null ;
832+ } )
833+ . filter ( x => x ) ;
836834
837- this . monaco . editor . setModelMarkers (
838- this . editor . getActiveCodeEditor ( ) . getModel ( ) ,
839- 'correction' ,
840- correctionMarkers
841- ) ;
842- } else {
843- this . monaco . editor . setModelMarkers (
844- this . editor . getActiveCodeEditor ( ) . getModel ( ) ,
845- 'correction' ,
846- [ ]
847- ) ;
835+ this . monaco . editor . setModelMarkers (
836+ activeEditor . getModel ( ) ,
837+ 'correction' ,
838+ correctionMarkers
839+ ) ;
840+ } else {
841+ this . monaco . editor . setModelMarkers (
842+ activeEditor . getModel ( ) ,
843+ 'correction' ,
844+ [ ]
845+ ) ;
846+ }
848847 }
849848 } ;
850849
@@ -1085,13 +1084,15 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
10851084 } ;
10861085
10871086 openModule = ( module : Module ) => {
1088- const path = getModulePath (
1089- this . sandbox . modules ,
1090- this . sandbox . directories ,
1091- module . id
1092- ) ;
1087+ if ( module . id ) {
1088+ const path = getModulePath (
1089+ this . sandbox . modules ,
1090+ this . sandbox . directories ,
1091+ module . id
1092+ ) ;
10931093
1094- this . editor . openFile ( path ) ;
1094+ this . editor . openFile ( path ) ;
1095+ }
10951096 } ;
10961097
10971098 swapDocuments = ( currentModule : Module , nextModule : Module ) => {
0 commit comments