Skip to content

Commit 32daee2

Browse files
authored
fix(editor): fix report error message when close tab in editor (#207)
1 parent 20c191d commit 32daee2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/controller/editor.tsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import { editor as monacoEditor, Uri } from 'mo/monaco';
2020

2121
import {
2222
EditorService,
23+
ExplorerService,
2324
IEditorService,
25+
IExplorerService,
2426
IStatusBarService,
2527
StatusBarService,
2628
} from 'mo/services';
@@ -56,11 +58,13 @@ export class EditorController extends Controller implements IEditorController {
5658
private editorStates = new Map();
5759
private readonly editorService: IEditorService;
5860
private readonly statusBarService: IStatusBarService;
61+
private readonly explorerService: IExplorerService;
5962

6063
constructor() {
6164
super();
6265
this.editorService = container.resolve(EditorService);
6366
this.statusBarService = container.resolve(StatusBarService);
67+
this.explorerService = container.resolve(ExplorerService);
6468
}
6569

6670
public open<T>(tab: IEditorTab<any>, groupId?: number) {
@@ -107,21 +111,24 @@ export class EditorController extends Controller implements IEditorController {
107111

108112
public updateCurrentValue = () => {
109113
const { current } = this.editorService.getState();
110-
const model = current?.editorInstance?.getModel();
111-
const newValue = model.getValue();
112-
current?.editorInstance?.executeEdits('update-value', [
113-
{
114-
range: model.getFullModelRange(),
115-
text: newValue,
116-
forceMoveMarkers: true,
117-
},
118-
]);
119-
current?.editorInstance?.focus();
114+
if (current) {
115+
const model = current?.editorInstance?.getModel();
116+
const newValue = model.getValue();
117+
current?.editorInstance?.executeEdits('update-value', [
118+
{
119+
range: model.getFullModelRange(),
120+
text: newValue,
121+
forceMoveMarkers: true,
122+
},
123+
]);
124+
current?.editorInstance?.focus();
125+
}
120126
};
121127

122128
public onCloseTab = (tabId?: string, groupId?: number) => {
123129
if (tabId && groupId) {
124130
this.editorService.closeTab(tabId, groupId);
131+
this.explorerService.forceUpdate();
125132
this.updateCurrentValue();
126133
this.emit(EditorEvent.OnCloseTab, tabId, groupId);
127134
}

0 commit comments

Comments
 (0)