Skip to content

Commit

Permalink
Fixed bug where there was a timing issue opening initial edit window
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Mar 19, 2019
1 parent ed6d14e commit d068cc3
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions webClient/src/app/editor/code-editor/monaco/monaco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,51 @@ export class MonacoService {

setMonacoModel(fileNode: ProjectContext, file: { contents: string, language: string }): Observable<void> {
return new Observable((obs) => {
const _editor = this.editorControl.editorCore.getValue().editor;
fileNode.model.contents = file['contents'];
this.editorControl.getRecommendedHighlightingModesForBuffer(fileNode).subscribe((supportLanguages: string[]) => {
let fileLang = 'plaintext';
if (file['language']) {
fileLang = file['language'];
} else if (fileNode.model.language) {
fileLang = fileNode.model.language;
} else if (supportLanguages[0]) {
fileLang = supportLanguages[0];
}
// sync language to context
fileNode.model.language = fileLang;
const model = {
value: file['contents'],
language: fileLang,
// language: 'json',
uri: this.generateUri(fileNode.model),
};
const duplicate: boolean = this.fileDuplicateChecker(model.uri);
let newModel;
if (!duplicate) {
newModel = _editor.createModel(model.value, model.language, model.uri);
} else {
newModel = _editor.getModel(model.uri);
}
newModel.onDidChangeContent((e: any) => {
this.fileContentChangeHandler(e, fileNode, newModel);
let coreSubscription = this.editorControl.editorCore
.subscribe((value)=> {
if (value && value.editor) {
const editorCore = value.editor;
//getValue().editor;

fileNode.model.contents = file['contents'];
this.editorControl.getRecommendedHighlightingModesForBuffer(fileNode).subscribe((supportLanguages: string[]) => {
let fileLang = 'plaintext';
if (file['language']) {
fileLang = file['language'];
} else if (fileNode.model.language) {
fileLang = fileNode.model.language;
} else if (supportLanguages[0]) {
fileLang = supportLanguages[0];
}
// sync language to context
fileNode.model.language = fileLang;
const model = {
value: file['contents'],
language: fileLang,
// language: 'json',
uri: this.generateUri(fileNode.model),
};
const duplicate: boolean = this.fileDuplicateChecker(model.uri);
let newModel;
if (!duplicate) {
newModel = editorCore.createModel(model.value, model.language, model.uri);
} else {
newModel = editorCore.getModel(model.uri);
}
newModel.onDidChangeContent((e: any) => {
this.fileContentChangeHandler(e, fileNode, newModel);
});
let editorSubscription = this.editorControl.editor.subscribe((value)=> {
if (value) {
value.setModel(newModel);
editorSubscription.unsubscribe();
obs.next();
}
});
});
coreSubscription.unsubscribe();
}
});
this.editorControl.editor.getValue().setModel(newModel);
obs.next();
});
});
}

Expand Down

0 comments on commit d068cc3

Please sign in to comment.