11import 'reflect-metadata' ;
22import { singleton , container } from 'tsyringe' ;
3- import { cloneDeep , isString } from 'lodash' ;
3+ import { cloneDeep } from 'lodash' ;
44import { Component } from 'mo/react' ;
55import {
66 EditorModel ,
@@ -205,6 +205,12 @@ export interface IEditorService extends Component<IEditor> {
205205 * @param tabId
206206 */
207207 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 ;
208214}
209215@singleton ( )
210216export class EditorService
@@ -325,11 +331,15 @@ export class EditorService
325331 updatedTab = Object . assign ( tabData , tab ) ;
326332 }
327333 if ( group . activeTab === tab . id ) {
328- isString ( editorValue ) &&
329- ! tabData ?. renderPane &&
330- this . setGroupEditorValue ( group , editorValue ) ;
331334 updatedTab = Object . assign ( group . tab , tab ) ;
332335 }
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+ }
333343 this . updateGroup ( groupId , group ) ;
334344
335345 if ( groupId === this . state . current ?. id ) {
@@ -345,11 +355,16 @@ export class EditorService
345355 }
346356
347357 if ( group . activeTab === tab . id ) {
348- isString ( editorValue ) &&
349- ! tabData ?. renderPane &&
350- this . setGroupEditorValue ( group , editorValue ) ;
351358 updatedTab = Object . assign ( group . tab , tab ) ;
352359 }
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+ }
353368 } ) ;
354369
355370 if ( current ?. activeTab === tab . id ) {
@@ -777,4 +792,10 @@ export class EditorService
777792 ) {
778793 this . subscribe ( EditorEvent . onActionsClick , callback ) ;
779794 }
795+
796+ public onEditorInstanceMount (
797+ callback : ( editorInstance : MonacoEditor . IStandaloneCodeEditor ) => void
798+ ) {
799+ this . subscribe ( EditorEvent . onEditorInstanceMount , callback ) ;
800+ }
780801}
0 commit comments