Skip to content

Commit

Permalink
fix: improve the forceUpdate after editor open and close (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung authored Sep 22, 2021
1 parent 8ad91e0 commit 50e0de2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/controller/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import { editor as MonacoEditor, Uri } from 'mo/monaco';

import {
EditorService,
ExplorerService,
IEditorService,
IExplorerService,
IStatusBarService,
StatusBarService,
} from 'mo/services';
Expand Down Expand Up @@ -60,13 +58,11 @@ export class EditorController extends Controller implements IEditorController {
private editorStates = new Map();
private readonly editorService: IEditorService;
private readonly statusBarService: IStatusBarService;
private readonly explorerService: IExplorerService;

constructor() {
super();
this.editorService = container.resolve(EditorService);
this.statusBarService = container.resolve(StatusBarService);
this.explorerService = container.resolve(ExplorerService);
}

public open<T>(tab: IEditorTab<any>, groupId?: number) {
Expand Down Expand Up @@ -117,7 +113,6 @@ export class EditorController extends Controller implements IEditorController {
public onCloseTab = (tabId?: string, groupId?: number) => {
if (tabId && groupId) {
this.editorService.closeTab(tabId, groupId);
this.explorerService.forceUpdate();
this.emit(EditorEvent.OnCloseTab, tabId, groupId);
}
};
Expand Down
3 changes: 0 additions & 3 deletions src/extensions/editorTree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ export const ExtendsEditorTree: IExtension = {

molecule.editorTree.onClose((tabId, groupId) => {
molecule.editor.closeTab(tabId, groupId);
molecule.explorer.forceUpdate();
});

molecule.editorTree.onCloseOthers((tabItem, groupId) => {
molecule.editor.closeOther(tabItem, groupId);
molecule.explorer.forceUpdate();
});

molecule.editorTree.onCloseSaved((groupId) => {
Expand All @@ -30,7 +28,6 @@ export const ExtendsEditorTree: IExtension = {
molecule.editor.closeAll(group.id!);
});
}
molecule.explorer.forceUpdate();
});

molecule.editorTree.onSaveAll((groupId) => {
Expand Down
3 changes: 2 additions & 1 deletion src/react/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneDeep } from 'lodash';
import { EventEmitter, GlobalEvent } from 'mo/common/event';

enum componentEvents {
Expand Down Expand Up @@ -55,7 +56,7 @@ export abstract class Component<S = any>
}

public forceUpdate() {
this.setState(Object.assign({}, this.state));
this.setState(cloneDeep(this.state));
}

public getState(): S {
Expand Down
9 changes: 9 additions & 0 deletions src/services/workbench/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { searchById } from '../helper';
import { editor as MonacoEditor, Uri } from 'mo/monaco';
import { IMenuItemProps } from 'mo/components';
import { ExplorerService, IExplorerService } from './explorer/explorerService';

export interface IEditorService extends Component<IEditor> {
/**
Expand Down Expand Up @@ -196,10 +197,12 @@ export class EditorService
implements IEditorService {
protected state: IEditor;
protected defaultActions: IEditorActionsProps[];
protected explorerService: IExplorerService;
constructor() {
super();
this.state = container.resolve(EditorModel);
this.defaultActions = getEditorInitialActions();
this.explorerService = container.resolve(ExplorerService);
}

public updateEditorOptions(options: IEditorOptions): void {
Expand Down Expand Up @@ -378,6 +381,7 @@ export class EditorService
() => {
const isOpened = this.isOpened(tabId);
!isOpened && this.disposeModel(tab);
this.explorerService.forceUpdate();
}
);
}
Expand Down Expand Up @@ -411,6 +415,7 @@ export class EditorService
this.setActive(groupId, tabId!);

this.disposeModel(removedTabs);
this.explorerService.forceUpdate();
}

public closeToRight(tab: IEditorTab, groupId: number) {
Expand Down Expand Up @@ -442,6 +447,7 @@ export class EditorService
});
this.setActive(groupId, tabId!);
this.disposeModel(removedTabs || []);
this.explorerService.forceUpdate();
}

public closeToLeft(tab: IEditorTab, groupId: number) {
Expand Down Expand Up @@ -473,6 +479,7 @@ export class EditorService
});
this.setActive(groupId, tabId!);
this.disposeModel(removedTabs || []);
this.explorerService.forceUpdate();
}

public getGroupById(groupId: number): IEditorGroup | undefined {
Expand Down Expand Up @@ -591,6 +598,7 @@ export class EditorService
current: group,
groups: [...groups],
});
this.explorerService.forceUpdate();
}

public onOpenTab(callback: (tab: IEditorTab) => void): void {
Expand Down Expand Up @@ -626,6 +634,7 @@ export class EditorService
() => {
// dispose all models in specific group
this.disposeModel(removed);
this.explorerService.forceUpdate();
}
);
}
Expand Down
1 change: 0 additions & 1 deletion src/services/workbench/explorer/folderTreeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ export class FolderTreeService

public onSelectFile(callback: (file: ITreeNodeItemProps) => void) {
this.subscribe(FolderTreeEvent.onSelectFile, callback);
this.explorerService.render();
}

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

0 comments on commit 50e0de2

Please sign in to comment.