Commit 675864e2 authored by Jacob Schatz's avatar Jacob Schatz

Add support for syntax highlighting any support lang for monaco.

parent 9c521c85
...@@ -16,7 +16,6 @@ export default class RepoCommitSection { ...@@ -16,7 +16,6 @@ export default class RepoCommitSection {
changedFiles() { changedFiles() {
const changedFileList = this.openedFiles const changedFileList = this.openedFiles
.filter(file => file.changed); .filter(file => file.changed);
console.log('changedFileList', changedFileList);
return changedFileList; return changedFileList;
}, },
}, },
......
...@@ -32,7 +32,6 @@ export default class RepoEditor { ...@@ -32,7 +32,6 @@ export default class RepoEditor {
Helper.monacoInstance = monaco; Helper.monacoInstance = monaco;
this.initVue(); this.initVue();
monaco.languages.getLanguages();
this.addMonacoEvents(); this.addMonacoEvents();
}); });
} }
...@@ -113,10 +112,13 @@ export default class RepoEditor { ...@@ -113,10 +112,13 @@ export default class RepoEditor {
self.monacoEditor.setModel( self.monacoEditor.setModel(
monaco.editor.createModel( monaco.editor.createModel(
this.blobRaw, this.blobRaw,
this.activeFile.mime_type, Helper
.getLanguageForFile(
this.activeFile,
monaco.languages.getLanguages()
),
), ),
); );
console.log(monaco.editor.getModels());
} }
}, },
}, },
......
...@@ -14,13 +14,19 @@ const RepoHelper = { ...@@ -14,13 +14,19 @@ const RepoHelper = {
? window.performance ? window.performance
: Date, : Date,
getLanguagesForMimeType(mimetypeNeedle) { getLanguageForFile(file, langs) {
const langs = window.monaco.languages.getLanguages(); const ext = `.${file.name.split('.').pop()}`;
langs.map((lang) => { let foundLang;
const hasLang = lang.mimetypes.some(mimetype => mimetypeNeedle === mimetype); if(langs.some((l) => {
if (hasLang) return lang.id; if(l.extensions && l.extensions.indexOf(ext) > -1) {
return lang; foundLang = l;
}); return true;
}
return false;
})) {
return foundLang.id
}
return 'plain';
}, },
blobURLtoParent(url) { blobURLtoParent(url) {
......
import Vue from 'vue'; import Service from './repo_service'
import Service from './repo_service'; import Helper from './repo_helper'
import Helper from './repo_helper'; import Vue from 'vue'
import Store from './repo_store'; import Store from './repo_store'
import RepoPreviousDirectory from './repo_prev_directory'; import RepoPreviousDirectory from './repo_prev_directory'
import RepoFileOptions from './repo_file_options'; import RepoFileOptions from './repo_file_options'
import RepoFile from './repo_file'; import RepoFile from './repo_file'
import RepoLoadingFile from './repo_loading_file'; import RepoLoadingFile from './repo_loading_file'
import RepoMiniMixin from './repo_mini_mixin'; import RepoMiniMixin from './repo_mini_mixin'
export default class RepoSidebar { export default class RepoSidebar {
constructor(url) { constructor(url) {
...@@ -35,35 +35,33 @@ export default class RepoSidebar { ...@@ -35,35 +35,33 @@ export default class RepoSidebar {
methods: { methods: {
addPopEventListener() { addPopEventListener() {
window.addEventListener('popstate', () => { window.addEventListener('popstate', () => {
if (location.href.indexOf('#') > -1) return; if(location.href.indexOf('#') > -1) return;
this.linkClicked({ this.linkClicked({
url: location.href, url: location.href
}); });
}); });
}, },
linkClicked(file) { linkClicked(file) {
console.log('link clicked')
let url = ''; let url = '';
if (typeof file === 'object') { if(typeof file === 'object') {
if (file.type === 'tree' && file.opened) { if(file.type === 'tree' && file.opened) {
Helper.removeChildFilesOfTree(file); Helper.removeChildFilesOfTree(file);
return; return;
} else {
url = file.url;
Service.url = url;
Helper.getContent(file);
} }
url = file.url; } else if(typeof file === 'string') {
Service.url = url;
Helper.getContent(file);
url = file.url;
Service.url = url;
Helper.getContent(file);
} else if (typeof file === 'string') {
// go back // go back
url = file; url = file;
Service.url = url; Service.url = url;
Helper.getContent(); Helper.getContent();
} }
}, }
}, },
}); });
} }
} }
\ No newline at end of file
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