Skip to content

Commit 4ef35a3

Browse files
committed
fix: update the editor value with the updateTab method (DTStack#714)
1 parent 46b3d8b commit 4ef35a3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/services/workbench/editorService.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'reflect-metadata';
22
import { singleton, container } from 'tsyringe';
3-
import cloneDeep from 'lodash/cloneDeep';
3+
import { cloneDeep, isString } from 'lodash';
44
import { Component } from 'mo/react';
55
import {
66
EditorModel,
@@ -41,6 +41,12 @@ export interface IEditorService extends Component<IEditor> {
4141
* @param groupId
4242
*/
4343
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;
4450
/**
4551
* Specify the Entry page of Workbench
4652
*/
@@ -308,6 +314,7 @@ export class EditorService
308314

309315
public updateTab(tab: IEditorTab, groupId?: UniqueId): IEditorTab {
310316
let updatedTab;
317+
const editorValue = tab?.data?.value;
311318
if (groupId) {
312319
const group = this.getGroupById(groupId);
313320

@@ -317,8 +324,9 @@ export class EditorService
317324
if (tabData) {
318325
updatedTab = Object.assign(tabData, tab);
319326
}
320-
321327
if (group.activeTab === tab.id) {
328+
isString(editorValue) &&
329+
this.setGroupEditorValue(group, editorValue);
322330
updatedTab = Object.assign(group.tab, tab);
323331
}
324332
this.updateGroup(groupId, group);
@@ -336,6 +344,8 @@ export class EditorService
336344
}
337345

338346
if (group.activeTab === tab.id) {
347+
isString(editorValue) &&
348+
this.setGroupEditorValue(group, editorValue);
339349
updatedTab = Object.assign(group.tab, tab);
340350
}
341351
});
@@ -349,9 +359,20 @@ export class EditorService
349359
groups,
350360
});
351361
}
362+
352363
return updatedTab;
353364
}
354365

366+
public setGroupEditorValue(group: IEditorGroup, value: string) {
367+
const model = group.editorInstance?.getModel();
368+
if (!model) return;
369+
370+
const currentValue = model?.getValue();
371+
if (currentValue !== value) {
372+
model?.setValue(value);
373+
}
374+
}
375+
355376
public closeTab(tabId: UniqueId, groupId: UniqueId) {
356377
const groupIndex = this.getGroupIndexById(groupId);
357378
if (groupIndex === -1) return;

0 commit comments

Comments
 (0)