Skip to content

monaco-editor: Find model by resource in SimpleEditorModelResolverService #85129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/vs/editor/standalone/browser/simpleServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ function withTypedEditor<T>(widget: editorCommon.IEditor, codeEditorCallback: (e
export class SimpleEditorModelResolverService implements ITextModelService {
public _serviceBrand: undefined;

private readonly modelService: IModelService | undefined;
private editor?: editorCommon.IEditor;

constructor(modelService: IModelService | undefined) {
this.modelService = modelService;
}

public setEditor(editor: editorCommon.IEditor): void {
this.editor = editor;
}
Expand Down Expand Up @@ -132,7 +137,7 @@ export class SimpleEditorModelResolverService implements ITextModelService {
}

private findModel(editor: ICodeEditor, resource: URI): ITextModel | null {
let model = editor.getModel();
let model = this.modelService ? this.modelService.getModel(resource) : editor.getModel();
if (model && model.uri.toString() !== resource.toString()) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/standalone/browser/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: H

let simpleEditorModelResolverService: SimpleEditorModelResolverService | null = null;
if (!services.has(ITextModelService)) {
simpleEditorModelResolverService = new SimpleEditorModelResolverService();
simpleEditorModelResolverService = new SimpleEditorModelResolverService(StaticServices.modelService.get());
services.set(ITextModelService, simpleEditorModelResolverService);
}

Expand Down