mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Do not use the global monaco
inside the editor
This commit is contained in:
parent
bb841e3bbe
commit
9545d58236
|
@ -31,6 +31,9 @@ import { StandaloneCodeEditorNLS } from 'vs/editor/common/standaloneStrings';
|
|||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
|
||||
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { ILanguageSelection, IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
/**
|
||||
* Description of an action contribution
|
||||
|
@ -364,7 +367,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
|
|||
@IStandaloneThemeService themeService: IStandaloneThemeService,
|
||||
@INotificationService notificationService: INotificationService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IAccessibilityService accessibilityService: IAccessibilityService
|
||||
@IAccessibilityService accessibilityService: IAccessibilityService,
|
||||
@IModelService modelService: IModelService,
|
||||
@IModeService modeService: IModeService,
|
||||
) {
|
||||
const options = { ..._options };
|
||||
updateConfigurationService(configurationService, options, false);
|
||||
|
@ -384,7 +389,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
|
|||
|
||||
let model: ITextModel | null;
|
||||
if (typeof _model === 'undefined') {
|
||||
model = (<any>self).monaco.editor.createModel(options.value || '', options.language || 'text/plain');
|
||||
model = createTextModel(modelService, modeService, options.value || '', options.language || 'text/plain', undefined);
|
||||
this._ownsModel = true;
|
||||
} else {
|
||||
model = _model;
|
||||
|
@ -507,3 +512,26 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
|
|||
return this.getModifiedEditor().addAction(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createTextModel(modelService: IModelService, modeService: IModeService, value: string, language: string | undefined, uri: URI | undefined): ITextModel {
|
||||
value = value || '';
|
||||
if (!language) {
|
||||
const firstLF = value.indexOf('\n');
|
||||
let firstLine = value;
|
||||
if (firstLF !== -1) {
|
||||
firstLine = value.substring(0, firstLF);
|
||||
}
|
||||
return doCreateModel(modelService, value, modeService.createByFilepathOrFirstLine(uri || null, firstLine), uri);
|
||||
}
|
||||
return doCreateModel(modelService, value, modeService.create(language), uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function doCreateModel(modelService: IModelService, value: string, languageSelection: ILanguageSelection, uri: URI | undefined): ITextModel {
|
||||
return modelService.createModel(value, languageSelection, uri);
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ import { FindMatch, ITextModel, TextModelResolvedOptions } from 'vs/editor/commo
|
|||
import * as modes from 'vs/editor/common/modes';
|
||||
import { NULL_STATE, nullTokenize } from 'vs/editor/common/modes/nullMode';
|
||||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { IWebWorkerOptions, MonacoWebWorker, createWebWorker as actualCreateWebWorker } from 'vs/editor/common/services/webWorker';
|
||||
import * as standaloneEnums from 'vs/editor/common/standalone/standaloneEnums';
|
||||
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer';
|
||||
import { SimpleEditorModelResolverService } from 'vs/editor/standalone/browser/simpleServices';
|
||||
import { IDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, IStandaloneCodeEditor, IStandaloneDiffEditor, StandaloneDiffEditor, StandaloneEditor } from 'vs/editor/standalone/browser/standaloneCodeEditor';
|
||||
import { IDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, IStandaloneCodeEditor, IStandaloneDiffEditor, StandaloneDiffEditor, StandaloneEditor, createTextModel } from 'vs/editor/standalone/browser/standaloneCodeEditor';
|
||||
import { DynamicStandaloneServices, IEditorOverrideServices, StaticServices } from 'vs/editor/standalone/browser/standaloneServices';
|
||||
import { IStandaloneThemeData, IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
|
||||
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
@ -42,6 +42,7 @@ import { IEditorProgressService } from 'vs/platform/progress/common/progress';
|
|||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
|
||||
import { splitLines } from 'vs/base/common/strings';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
|
@ -87,7 +88,9 @@ export function create(domElement: HTMLElement, options?: IStandaloneEditorConst
|
|||
services.get(IStandaloneThemeService),
|
||||
services.get(INotificationService),
|
||||
services.get(IConfigurationService),
|
||||
services.get(IAccessibilityService)
|
||||
services.get(IAccessibilityService),
|
||||
services.get(IModelService),
|
||||
services.get(IModeService),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -140,27 +143,18 @@ export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: ID
|
|||
return new DiffNavigator(diffEditor, opts);
|
||||
}
|
||||
|
||||
function doCreateModel(value: string, languageSelection: ILanguageSelection, uri?: URI): ITextModel {
|
||||
return StaticServices.modelService.get().createModel(value, languageSelection, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new editor model.
|
||||
* You can specify the language that should be set for this model or let the language be inferred from the `uri`.
|
||||
*/
|
||||
export function createModel(value: string, language?: string, uri?: URI): ITextModel {
|
||||
value = value || '';
|
||||
|
||||
if (!language) {
|
||||
let firstLF = value.indexOf('\n');
|
||||
let firstLine = value;
|
||||
if (firstLF !== -1) {
|
||||
firstLine = value.substring(0, firstLF);
|
||||
}
|
||||
|
||||
return doCreateModel(value, StaticServices.modeService.get().createByFilepathOrFirstLine(uri || null, firstLine), uri);
|
||||
}
|
||||
return doCreateModel(value, StaticServices.modeService.get().create(language), uri);
|
||||
return createTextModel(
|
||||
StaticServices.modelService.get(),
|
||||
StaticServices.modeService.get(),
|
||||
value,
|
||||
language,
|
||||
uri
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue