Commit 928fedaa by Alexander Zobnin

code-editor: minor refactor

parent bf8171fd
///<reference path="../../../headers/common.d.ts" /> ///<reference path="../../../headers/common.d.ts" />
// import angular from 'angular';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import ace from 'ace'; import ace from 'ace';
...@@ -16,30 +15,33 @@ function fixModuleUrl(moduleType, name) { ...@@ -16,30 +15,33 @@ function fixModuleUrl(moduleType, name) {
ace.config.setModuleUrl(aceModeName, ACE_SRC_BASE + componentName); ace.config.setModuleUrl(aceModeName, ACE_SRC_BASE + componentName);
} }
fixModuleUrl("theme", "solarized_dark");
fixModuleUrl("ext", "language_tools"); fixModuleUrl("ext", "language_tools");
let editorTemplate = `<div></div>`; let editorTemplate = `<div></div>`;
function link(scope, elem, attrs) { function link(scope, elem, attrs) {
// Options
let langMode = attrs.mode || 'text';
let theme = "solarized_dark";
let aceElem = elem.get(0); let aceElem = elem.get(0);
let codeEditor = ace.edit(aceElem); let codeEditor = ace.edit(aceElem);
let editorSession = codeEditor.getSession(); let editorSession = codeEditor.getSession();
codeEditor.setTheme("ace/theme/solarized_dark");
codeEditor.setHighlightActiveLine(false); codeEditor.setHighlightActiveLine(false);
codeEditor.setShowPrintMargin(false); codeEditor.setShowPrintMargin(false);
// disable depreacation warning // disable depreacation warning
codeEditor.$blockScrolling = Infinity; codeEditor.$blockScrolling = Infinity;
setLangMode(); codeEditor.setAutoScrollEditorIntoView(true);
setThemeMode(theme);
setLangMode(langMode);
codeEditor.setValue(scope.content); codeEditor.setValue(scope.content);
codeEditor.clearSelection(); codeEditor.clearSelection();
elem.addClass("gf-code-editor"); elem.addClass("gf-code-editor");
let textarea = elem.find("textarea"); let textarea = elem.find("textarea");
textarea.addClass('gf-form-input width-25'); textarea.addClass('gf-form-input');
textarea.attr("rows", "4");
editorSession.on('change', (e) => { editorSession.on('change', (e) => {
scope.$apply(() => { scope.$apply(() => {
...@@ -48,8 +50,7 @@ function link(scope, elem, attrs) { ...@@ -48,8 +50,7 @@ function link(scope, elem, attrs) {
}); });
}); });
function setLangMode() { function setLangMode(lang) {
let lang = attrs.mode || 'text';
let aceModeName = `ace/mode/${lang}`; let aceModeName = `ace/mode/${lang}`;
fixModuleUrl("mode", lang); fixModuleUrl("mode", lang);
fixModuleUrl("snippets", lang); fixModuleUrl("snippets", lang);
...@@ -62,6 +63,12 @@ function link(scope, elem, attrs) { ...@@ -62,6 +63,12 @@ function link(scope, elem, attrs) {
}); });
}); });
} }
function setThemeMode(theme) {
fixModuleUrl("theme", theme);
let aceThemeName = `ace/theme/${theme}`;
codeEditor.setTheme(aceThemeName);
}
} }
export function codeEditorDirective() { export function codeEditorDirective() {
......
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