Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
instance,
isDiff,
} = {}) {
if (!instance) {
return null;
}
const uriFilePath = joinPaths(URI_PREFIX, blobGlobalId, blobPath);
const uri = Uri.file(uriFilePath);
const existingModel = monacoEditor.getModel(uri);
const model = existingModel || monacoEditor.createModel(blobContent, undefined, uri);
if (!isDiff) {
instance.setModel(model);
return model;
}
const diffModel = {
original: monacoEditor.createModel(
blobOriginalContent,
EditorLite.getModelLanguage(model.uri.path),
),
modified: model,
};
instance.setModel(diffModel);
return diffModel;
}
constructor(file, head = null) {
this.disposable = new Disposable();
this.file = file;
this.head = head;
this.content = file.content !== '' || file.deleted ? file.content : file.raw;
this.options = { ...defaultModelOptions };
this.disposable.add(
(this.originalModel = monacoEditor.createModel(
head ? head.content : this.file.raw,
undefined,
new Uri('gitlab', false, `original/${this.path}`),
)),
(this.model = monacoEditor.createModel(
this.content,
undefined,
new Uri('gitlab', false, this.path),
)),
);
if (this.file.mrChange) {
this.disposable.add(
(this.baseModel = monacoEditor.createModel(
this.file.baseRaw,
undefined,
new Uri('gitlab', false, `target/${this.path}`),
import { Uri, editor } from "monaco-editor";
import defaultCode from "raw-loader!./assets/main.txt";
import defaultTSConfig from "raw-loader!./assets/tsconfig.txt";
export const codeEditorModel = editor.createModel(
defaultCode,
"typescript",
Uri.parse("file:///main.tsx")
);
export const tsConfigEditorModel = editor.createModel(
defaultTSConfig,
"json",
Uri.parse("file:///tsconfig.json")
);
import { Uri, editor } from "monaco-editor";
import defaultCode from "raw-loader!./assets/main.txt";
import defaultTSConfig from "raw-loader!./assets/tsconfig.txt";
export const codeEditorModel = editor.createModel(
defaultCode,
"typescript",
Uri.parse("file:///main.tsx")
);
export const tsConfigEditorModel = editor.createModel(
defaultTSConfig,
"json",
Uri.parse("file:///tsconfig.json")
);
constructor(file, head = null) {
this.disposable = new Disposable();
this.file = file;
this.head = head;
this.content = file.content !== '' || file.deleted ? file.content : file.raw;
this.options = { ...defaultModelOptions };
this.disposable.add(
(this.originalModel = monacoEditor.createModel(
head ? head.content : this.file.raw,
undefined,
new Uri('gitlab', false, `original/${this.path}`),
)),
(this.model = monacoEditor.createModel(
this.content,
undefined,
new Uri('gitlab', false, this.path),
)),
);
if (this.file.mrChange) {
this.disposable.add(
(this.baseModel = monacoEditor.createModel(
this.file.baseRaw,
undefined,
new Uri('gitlab', false, `target/${this.path}`),
)),
);
}
this.events = new Set();
this.disposable.add(
(this.originalModel = monacoEditor.createModel(
head ? head.content : this.file.raw,
undefined,
new Uri('gitlab', false, `original/${this.path}`),
)),
(this.model = monacoEditor.createModel(
this.content,
undefined,
new Uri('gitlab', false, this.path),
)),
);
if (this.file.mrChange) {
this.disposable.add(
(this.baseModel = monacoEditor.createModel(
this.file.baseRaw,
undefined,
new Uri('gitlab', false, `target/${this.path}`),
)),
);
}
this.events = new Set();
this.updateContent = this.updateContent.bind(this);
this.updateNewContent = this.updateNewContent.bind(this);
this.dispose = this.dispose.bind(this);
eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose);
eventHub.$on(`editor.update.model.content.${this.file.key}`, this.updateContent);
eventHub.$on(`editor.update.model.new.content.${this.file.key}`, this.updateNewContent);
static createEditorModel({
blobPath,
blobContent,
blobOriginalContent,
blobGlobalId,
instance,
isDiff,
} = {}) {
if (!instance) {
return null;
}
const uriFilePath = joinPaths(URI_PREFIX, blobGlobalId, blobPath);
const uri = Uri.file(uriFilePath);
const existingModel = monacoEditor.getModel(uri);
const model = existingModel || monacoEditor.createModel(blobContent, undefined, uri);
if (!isDiff) {
instance.setModel(model);
return model;
}
const diffModel = {
original: monacoEditor.createModel(
blobOriginalContent,
EditorLite.getModelLanguage(model.uri.path),
),
modified: model,
};
instance.setModel(diffModel);
return diffModel;
}