Commit 737aadd1 authored by Jacob Schatz's avatar Jacob Schatz Committed by Eric Eastwood

Move duplicated code to help

parent 48a2d2d3
......@@ -29,12 +29,10 @@ const RepoEditor = {
this.addMonacoEvents();
const languages = this.monaco.languages.getLanguages();
const languageID = Helper.getLanguageIDForFile(this.activeFile, languages);
Helper.setMonacoModelFromLanguage();
this.showHide();
const newModel = this.monaco.editor.createModel(this.blobRaw, languageID);
Helper.monacoInstance.setModel(newModel);
}).catch(Helper.loadingError);
},
......@@ -114,14 +112,7 @@ const RepoEditor = {
this.showHide();
if (this.isTree) return;
Helper.monacoInstance.setModel(null);
const languages = this.monaco.languages.getLanguages();
const languageID = Helper.getLanguageIDForFile(this.activeFile, languages);
const newModel = this.monaco.editor.createModel(this.blobRaw, languageID);
Helper.monacoInstance.setModel(newModel);
Helper.setMonacoModelFromLanguage();
},
},
};
......
......@@ -46,6 +46,14 @@ const RepoHelper = {
return foundLang ? foundLang.id : 'plaintext';
},
setMonacoModelFromLanguage() {
RepoHelper.monacoInstance.setModel(null);
const languages = Store.monaco.languages.getLanguages();
const languageID = RepoHelper.getLanguageIDForFile(Store.activeFile, languages);
const newModel = Store.monaco.editor.createModel(Store.blobRaw, languageID);
RepoHelper.monacoInstance.setModel(newModel);
},
findLanguage(ext, langs) {
return langs.find(lang => lang.extensions && lang.extensions.indexOf(`.${ext}`) > -1);
},
......@@ -293,7 +301,8 @@ const RepoHelper = {
return Store.openedFiles.find(openedFile => Store.activeFile.url === openedFile.url);
},
loadingError() {
loadingError(e) {
console.log(e);
Flash('Unable to load this content at this time.');
},
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment