Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This is needed because the content for the file might have been modified externally
// Use `pushEditOperations` instead of `setValue` or `applyEdits` to preserve undo stack
model.pushEditOperations(
[],
[
{
range: model.getFullModelRange(),
text: value,
},
]
);
} else {
model = monaco.editor.createModel(
value,
this._getLanguage(this.props.path),
new monaco.Uri().with({ path })
);
model.updateOptions({
tabSize: 2,
insertSpaces: true,
});
}
this.editor.setModel(model);
return model;
};
// This is needed because the content for the file might have been modified externally
// Use `pushEditOperations` instead of `setValue` or `applyEdits` to preserve undo stack
model.pushEditOperations(
[],
[
{
range: model.getFullModelRange(),
text: value,
},
]
);
} else {
model = monaco.editor.createModel(
value,
this._getLanguage(this.props.path),
new monaco.Uri().with({ path }),
);
model.updateOptions({
tabSize: 2,
insertSpaces: true,
});
}
this.editor.setModel(model);
return model;
};
describe('Base editor', () => {
let editorEl;
let editor;
const blobContent = 'Foo Bar';
const blobPath = 'test.md';
const uri = new Uri('gitlab', false, blobPath);
const fakeModel = { foo: 'bar' };
beforeEach(() => {
setFixtures('<div data-editor-loading="" id="editor"></div>');
editorEl = document.getElementById('editor');
editor = new Editor();
});
afterEach(() => {
editor.dispose();
editorEl.remove();
});
it('initializes Editor with basic properties', () => {
expect(editor).toBeDefined();
expect(editor.editorEl).toBe(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.updateContent = this.updateContent.bind(this);
this.updateNewContent = this.updateNewContent.bind(this);
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);
}