1
1
import 'reflect-metadata' ;
2
2
import { singleton , container } from 'tsyringe' ;
3
- import cloneDeep from 'lodash/cloneDeep ' ;
3
+ import { cloneDeep , isString } from 'lodash' ;
4
4
import { Component } from 'mo/react' ;
5
5
import {
6
6
EditorModel ,
@@ -41,6 +41,12 @@ export interface IEditorService extends Component<IEditor> {
41
41
* @param groupId
42
42
*/
43
43
updateTab ( tab : IEditorTab , groupId ?: UniqueId ) : IEditorTab ;
44
+ /**
45
+ * Updates the editor content for a specific group
46
+ * @param group The editorInstance is required
47
+ * @param value
48
+ */
49
+ setGroupEditorValue ( group : IEditorGroup , value : string ) : void ;
44
50
/**
45
51
* Specify the Entry page of Workbench
46
52
*/
@@ -308,6 +314,7 @@ export class EditorService
308
314
309
315
public updateTab ( tab : IEditorTab , groupId ?: UniqueId ) : IEditorTab {
310
316
let updatedTab ;
317
+ const editorValue = tab ?. data ?. value ;
311
318
if ( groupId ) {
312
319
const group = this . getGroupById ( groupId ) ;
313
320
@@ -317,8 +324,9 @@ export class EditorService
317
324
if ( tabData ) {
318
325
updatedTab = Object . assign ( tabData , tab ) ;
319
326
}
320
-
321
327
if ( group . activeTab === tab . id ) {
328
+ isString ( editorValue ) &&
329
+ this . setGroupEditorValue ( group , editorValue ) ;
322
330
updatedTab = Object . assign ( group . tab , tab ) ;
323
331
}
324
332
this . updateGroup ( groupId , group ) ;
@@ -336,6 +344,8 @@ export class EditorService
336
344
}
337
345
338
346
if ( group . activeTab === tab . id ) {
347
+ isString ( editorValue ) &&
348
+ this . setGroupEditorValue ( group , editorValue ) ;
339
349
updatedTab = Object . assign ( group . tab , tab ) ;
340
350
}
341
351
} ) ;
@@ -349,9 +359,20 @@ export class EditorService
349
359
groups,
350
360
} ) ;
351
361
}
362
+
352
363
return updatedTab ;
353
364
}
354
365
366
+ public setGroupEditorValue ( group : IEditorGroup , value : string ) {
367
+ const modal = group . editorInstance ?. getModel ( ) ;
368
+ if ( ! modal ) return ;
369
+
370
+ const currentValue = modal ?. getValue ( ) ;
371
+ if ( currentValue !== value ) {
372
+ modal ?. setValue ( value ) ;
373
+ }
374
+ }
375
+
355
376
public closeTab ( tabId : UniqueId , groupId : UniqueId ) {
356
377
const groupIndex = this . getGroupIndexById ( groupId ) ;
357
378
if ( groupIndex === - 1 ) return ;
0 commit comments