1
1
import 'reflect-metadata' ;
2
2
import { singleton , container } from 'tsyringe' ;
3
- import { cloneDeep , isString } from 'lodash' ;
3
+ import { cloneDeep } from 'lodash' ;
4
4
import { Component } from 'mo/react' ;
5
5
import {
6
6
EditorModel ,
@@ -205,6 +205,12 @@ export interface IEditorService extends Component<IEditor> {
205
205
* @param tabId
206
206
*/
207
207
getGroupIdByTab ( tabId : UniqueId ) : UniqueId | null ;
208
+ /**
209
+ * Listen to the editor instance mount event
210
+ */
211
+ onEditorInstanceMount (
212
+ callback : ( editorInstance : MonacoEditor . IStandaloneCodeEditor ) => void
213
+ ) : void ;
208
214
}
209
215
@singleton ( )
210
216
export class EditorService
@@ -325,11 +331,15 @@ export class EditorService
325
331
updatedTab = Object . assign ( tabData , tab ) ;
326
332
}
327
333
if ( group . activeTab === tab . id ) {
328
- isString ( editorValue ) &&
329
- ! tabData ?. renderPane &&
330
- this . setGroupEditorValue ( group , editorValue ) ;
331
334
updatedTab = Object . assign ( group . tab , tab ) ;
332
335
}
336
+ // Update model's value
337
+ const model = MonacoEditor . getModel (
338
+ Uri . parse ( tab . id . toString ( ) )
339
+ ) ;
340
+ if ( model ) {
341
+ model . setValue ( editorValue || '' ) ;
342
+ }
333
343
this . updateGroup ( groupId , group ) ;
334
344
335
345
if ( groupId === this . state . current ?. id ) {
@@ -345,11 +355,16 @@ export class EditorService
345
355
}
346
356
347
357
if ( group . activeTab === tab . id ) {
348
- isString ( editorValue ) &&
349
- ! tabData ?. renderPane &&
350
- this . setGroupEditorValue ( group , editorValue ) ;
351
358
updatedTab = Object . assign ( group . tab , tab ) ;
352
359
}
360
+
361
+ // Update model's value
362
+ const model = MonacoEditor . getModel (
363
+ Uri . parse ( tab . id . toString ( ) )
364
+ ) ;
365
+ if ( model ) {
366
+ model . setValue ( editorValue || '' ) ;
367
+ }
353
368
} ) ;
354
369
355
370
if ( current ?. activeTab === tab . id ) {
@@ -777,4 +792,10 @@ export class EditorService
777
792
) {
778
793
this . subscribe ( EditorEvent . onActionsClick , callback ) ;
779
794
}
795
+
796
+ public onEditorInstanceMount (
797
+ callback : ( editorInstance : MonacoEditor . IStandaloneCodeEditor ) => void
798
+ ) {
799
+ this . subscribe ( EditorEvent . onEditorInstanceMount , callback ) ;
800
+ }
780
801
}
0 commit comments