2013-09-03 15:47:59 +00:00
|
|
|
define(["file", "command", "settings!ace,user", "dom2"], function(File, command, Settings) {
|
2013-08-20 00:53:03 +00:00
|
|
|
/*
|
|
|
|
Module for loading the editor, adding window resizing and other events. Returns the editor straight from Ace.
|
|
|
|
*/
|
2013-09-03 15:47:59 +00:00
|
|
|
var userConfig = Settings.get("user");
|
|
|
|
var aceConfig = Settings.get("ace");
|
2013-08-20 00:53:03 +00:00
|
|
|
|
|
|
|
var editor = window.editor = ace.edit("editor");
|
|
|
|
|
2013-08-23 23:03:46 +00:00
|
|
|
var themes = document.querySelector(".theme");
|
|
|
|
|
2013-09-02 01:26:22 +00:00
|
|
|
//one-time startup
|
|
|
|
var init = function() {
|
2013-09-03 15:47:59 +00:00
|
|
|
aceConfig.themes.forEach(function(theme) {
|
2013-09-02 01:26:22 +00:00
|
|
|
var option = document.createElement("option");
|
2013-09-15 17:37:44 +00:00
|
|
|
option.innerHTML = theme.label;
|
2013-09-02 01:26:22 +00:00
|
|
|
option.setAttribute("value", theme.name);
|
|
|
|
themes.append(option);
|
|
|
|
});
|
2013-09-14 21:08:25 +00:00
|
|
|
if (userConfig.emulateVim) {
|
|
|
|
ace.require("ace/lib/net").loadScript("js/ace/keybinding-vim.js", function() {
|
|
|
|
editor.setKeyboardHandler(ace.require("ace/keyboard/vim").handler);
|
|
|
|
});
|
|
|
|
}
|
2013-09-02 01:26:22 +00:00
|
|
|
reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
//reloaded when settings change
|
|
|
|
var reset = function() {
|
2013-09-04 19:26:09 +00:00
|
|
|
userConfig = Settings.get("user");
|
2013-09-03 15:47:59 +00:00
|
|
|
themes.value = userConfig.defaultTheme;
|
2013-09-02 01:26:22 +00:00
|
|
|
editor.setTheme("ace/theme/" + themes.value);
|
2013-09-20 15:08:41 +00:00
|
|
|
editor.setShowPrintMargin(userConfig.showMargin || false);
|
|
|
|
editor.setPrintMarginColumn(userConfig.wrapLimit || 80);
|
2013-10-24 19:32:30 +00:00
|
|
|
editor.setShowInvisibles(userConfig.showWhitespace || false);
|
2013-09-10 23:26:36 +00:00
|
|
|
editor.container.style.fontSize = userConfig.fontSize ? userConfig.fontSize + "px" : null;
|
|
|
|
editor.container.style.fontFamily = userConfig.fontFamily || null;
|
2013-10-28 16:18:43 +00:00
|
|
|
ace.config.loadModule("ace/ext/language_tools", function() {
|
|
|
|
editor.setOptions({
|
|
|
|
enableBasicAutocompletion: userConfig.autocomplete
|
|
|
|
});
|
|
|
|
});
|
2013-09-10 23:26:36 +00:00
|
|
|
};
|
2013-09-02 01:26:22 +00:00
|
|
|
|
|
|
|
command.on("init:startup", init);
|
|
|
|
command.on("init:restart", reset);
|
2013-08-23 23:03:46 +00:00
|
|
|
|
|
|
|
command.on("editor:theme", function(theme) {
|
|
|
|
editor.setTheme("ace/theme/" + theme);
|
2013-09-05 15:28:40 +00:00
|
|
|
editor.focus();
|
2013-08-23 23:03:46 +00:00
|
|
|
});
|
2013-09-04 23:36:33 +00:00
|
|
|
|
|
|
|
//disable focusing on the editor except by program
|
|
|
|
document.find("textarea").setAttribute("tabindex", -1);
|
2013-08-23 23:03:46 +00:00
|
|
|
|
2013-08-20 00:53:03 +00:00
|
|
|
return editor;
|
|
|
|
|
|
|
|
});
|