Skip to content

Commit 50e0de2

Browse files
authored
fix: improve the forceUpdate after editor open and close (#441)
1 parent 8ad91e0 commit 50e0de2

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

src/controller/editor.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import { editor as MonacoEditor, Uri } from 'mo/monaco';
2222

2323
import {
2424
EditorService,
25-
ExplorerService,
2625
IEditorService,
27-
IExplorerService,
2826
IStatusBarService,
2927
StatusBarService,
3028
} from 'mo/services';
@@ -60,13 +58,11 @@ export class EditorController extends Controller implements IEditorController {
6058
private editorStates = new Map();
6159
private readonly editorService: IEditorService;
6260
private readonly statusBarService: IStatusBarService;
63-
private readonly explorerService: IExplorerService;
6461

6562
constructor() {
6663
super();
6764
this.editorService = container.resolve(EditorService);
6865
this.statusBarService = container.resolve(StatusBarService);
69-
this.explorerService = container.resolve(ExplorerService);
7066
}
7167

7268
public open<T>(tab: IEditorTab<any>, groupId?: number) {
@@ -117,7 +113,6 @@ export class EditorController extends Controller implements IEditorController {
117113
public onCloseTab = (tabId?: string, groupId?: number) => {
118114
if (tabId && groupId) {
119115
this.editorService.closeTab(tabId, groupId);
120-
this.explorerService.forceUpdate();
121116
this.emit(EditorEvent.OnCloseTab, tabId, groupId);
122117
}
123118
};

src/extensions/editorTree/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export const ExtendsEditorTree: IExtension = {
99

1010
molecule.editorTree.onClose((tabId, groupId) => {
1111
molecule.editor.closeTab(tabId, groupId);
12-
molecule.explorer.forceUpdate();
1312
});
1413

1514
molecule.editorTree.onCloseOthers((tabItem, groupId) => {
1615
molecule.editor.closeOther(tabItem, groupId);
17-
molecule.explorer.forceUpdate();
1816
});
1917

2018
molecule.editorTree.onCloseSaved((groupId) => {
@@ -30,7 +28,6 @@ export const ExtendsEditorTree: IExtension = {
3028
molecule.editor.closeAll(group.id!);
3129
});
3230
}
33-
molecule.explorer.forceUpdate();
3431
});
3532

3633
molecule.editorTree.onSaveAll((groupId) => {

src/react/component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cloneDeep } from 'lodash';
12
import { EventEmitter, GlobalEvent } from 'mo/common/event';
23

34
enum componentEvents {
@@ -55,7 +56,7 @@ export abstract class Component<S = any>
5556
}
5657

5758
public forceUpdate() {
58-
this.setState(Object.assign({}, this.state));
59+
this.setState(cloneDeep(this.state));
5960
}
6061

6162
public getState(): S {

src/services/workbench/editorService.ts

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { searchById } from '../helper';
1818
import { editor as MonacoEditor, Uri } from 'mo/monaco';
1919
import { IMenuItemProps } from 'mo/components';
20+
import { ExplorerService, IExplorerService } from './explorer/explorerService';
2021

2122
export interface IEditorService extends Component<IEditor> {
2223
/**
@@ -196,10 +197,12 @@ export class EditorService
196197
implements IEditorService {
197198
protected state: IEditor;
198199
protected defaultActions: IEditorActionsProps[];
200+
protected explorerService: IExplorerService;
199201
constructor() {
200202
super();
201203
this.state = container.resolve(EditorModel);
202204
this.defaultActions = getEditorInitialActions();
205+
this.explorerService = container.resolve(ExplorerService);
203206
}
204207

205208
public updateEditorOptions(options: IEditorOptions): void {
@@ -378,6 +381,7 @@ export class EditorService
378381
() => {
379382
const isOpened = this.isOpened(tabId);
380383
!isOpened && this.disposeModel(tab);
384+
this.explorerService.forceUpdate();
381385
}
382386
);
383387
}
@@ -411,6 +415,7 @@ export class EditorService
411415
this.setActive(groupId, tabId!);
412416

413417
this.disposeModel(removedTabs);
418+
this.explorerService.forceUpdate();
414419
}
415420

416421
public closeToRight(tab: IEditorTab, groupId: number) {
@@ -442,6 +447,7 @@ export class EditorService
442447
});
443448
this.setActive(groupId, tabId!);
444449
this.disposeModel(removedTabs || []);
450+
this.explorerService.forceUpdate();
445451
}
446452

447453
public closeToLeft(tab: IEditorTab, groupId: number) {
@@ -473,6 +479,7 @@ export class EditorService
473479
});
474480
this.setActive(groupId, tabId!);
475481
this.disposeModel(removedTabs || []);
482+
this.explorerService.forceUpdate();
476483
}
477484

478485
public getGroupById(groupId: number): IEditorGroup | undefined {
@@ -591,6 +598,7 @@ export class EditorService
591598
current: group,
592599
groups: [...groups],
593600
});
601+
this.explorerService.forceUpdate();
594602
}
595603

596604
public onOpenTab(callback: (tab: IEditorTab) => void): void {
@@ -626,6 +634,7 @@ export class EditorService
626634
() => {
627635
// dispose all models in specific group
628636
this.disposeModel(removed);
637+
this.explorerService.forceUpdate();
629638
}
630639
);
631640
}

src/services/workbench/explorer/folderTreeService.ts

-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ export class FolderTreeService
343343

344344
public onSelectFile(callback: (file: ITreeNodeItemProps) => void) {
345345
this.subscribe(FolderTreeEvent.onSelectFile, callback);
346-
this.explorerService.render();
347346
}
348347

349348
public onDropTree = (treeData: ITreeNodeItemProps[]) => {

0 commit comments

Comments
 (0)