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