Skip to content

Commit

Permalink
fix(editor): fix report error message when close tab in editor (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung authored Jun 28, 2021
1 parent 20c191d commit 32daee2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/controller/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { editor as monacoEditor, Uri } from 'mo/monaco';

import {
EditorService,
ExplorerService,
IEditorService,
IExplorerService,
IStatusBarService,
StatusBarService,
} from 'mo/services';
Expand Down Expand Up @@ -56,11 +58,13 @@ 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 @@ -107,21 +111,24 @@ export class EditorController extends Controller implements IEditorController {

public updateCurrentValue = () => {
const { current } = this.editorService.getState();
const model = current?.editorInstance?.getModel();
const newValue = model.getValue();
current?.editorInstance?.executeEdits('update-value', [
{
range: model.getFullModelRange(),
text: newValue,
forceMoveMarkers: true,
},
]);
current?.editorInstance?.focus();
if (current) {
const model = current?.editorInstance?.getModel();
const newValue = model.getValue();
current?.editorInstance?.executeEdits('update-value', [
{
range: model.getFullModelRange(),
text: newValue,
forceMoveMarkers: true,
},
]);
current?.editorInstance?.focus();
}
};

public onCloseTab = (tabId?: string, groupId?: number) => {
if (tabId && groupId) {
this.editorService.closeTab(tabId, groupId);
this.explorerService.forceUpdate();
this.updateCurrentValue();
this.emit(EditorEvent.OnCloseTab, tabId, groupId);
}
Expand Down

0 comments on commit 32daee2

Please sign in to comment.