UNPKG

ares-ide

Version:

A browser-based code editor and UI designer for Enyo 2 projects

1,638 lines (1,419 loc) 220 kB
/* ***** BEGIN LICENSE BLOCK ***** * Distributed under the BSD license: * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ***** END LICENSE BLOCK ***** */ define('kitchen-sink/demo', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/multi_select', 'ace/ext/spellcheck', 'kitchen-sink/inline_editor', 'kitchen-sink/dev_util', 'kitchen-sink/file_drop', 'ace/config', 'ace/lib/dom', 'ace/lib/net', 'ace/lib/lang', 'ace/lib/useragent', 'ace/lib/event', 'ace/theme/textmate', 'ace/edit_session', 'ace/undomanager', 'ace/keyboard/hash_handler', 'ace/virtual_renderer', 'ace/editor', 'ace/ext/whitespace', 'kitchen-sink/doclist', 'ace/ext/modelist', 'kitchen-sink/layout', 'kitchen-sink/token_tooltip', 'kitchen-sink/util', 'ace/ext/elastic_tabstops_lite', 'ace/incremental_search', 'ace/worker/worker_client', 'ace/split', 'ace/keyboard/vim', 'ace/ext/statusbar', 'ace/ext/emmet', 'ace/snippets', 'ace/ext/language_tools'], function(require, exports, module) { require("ace/lib/fixoldbrowsers"); require("ace/multi_select"); require("ace/ext/spellcheck"); require("./inline_editor"); require("./dev_util"); require("./file_drop"); var config = require("ace/config"); config.init(); var env = {}; var dom = require("ace/lib/dom"); var net = require("ace/lib/net"); var lang = require("ace/lib/lang"); var useragent = require("ace/lib/useragent"); var event = require("ace/lib/event"); var theme = require("ace/theme/textmate"); var EditSession = require("ace/edit_session").EditSession; var UndoManager = require("ace/undomanager").UndoManager; var HashHandler = require("ace/keyboard/hash_handler").HashHandler; var Renderer = require("ace/virtual_renderer").VirtualRenderer; var Editor = require("ace/editor").Editor; var whitespace = require("ace/ext/whitespace"); var doclist = require("./doclist"); var modelist = require("ace/ext/modelist"); var layout = require("./layout"); var TokenTooltip = require("./token_tooltip").TokenTooltip; var util = require("./util"); var saveOption = util.saveOption; var fillDropdown = util.fillDropdown; var bindCheckbox = util.bindCheckbox; var bindDropdown = util.bindDropdown; var ElasticTabstopsLite = require("ace/ext/elastic_tabstops_lite").ElasticTabstopsLite; var IncrementalSearch = require("ace/incremental_search").IncrementalSearch; var workerModule = require("ace/worker/worker_client"); if (location.href.indexOf("noworker") !== -1) { workerModule.WorkerClient = workerModule.UIWorkerClient; } var container = document.getElementById("editor-container"); var Split = require("ace/split").Split; var split = new Split(container, theme, 1); env.editor = split.getEditor(0); split.on("focus", function(editor) { env.editor = editor; updateUIEditorOptions(); }); env.split = split; window.env = env; var consoleEl = dom.createElement("div"); container.parentNode.appendChild(consoleEl); consoleEl.style.cssText = "position:fixed; bottom:1px; right:0;\ border:1px solid #baf; z-index:100"; var cmdLine = new layout.singleLineEditor(consoleEl); cmdLine.editor = env.editor; env.editor.cmdLine = cmdLine; env.editor.showCommandLine = function(val) { this.cmdLine.focus(); if (typeof val == "string") this.cmdLine.setValue(val, 1); }; env.editor.commands.addCommands([{ name: "gotoline", bindKey: {win: "Ctrl-L", mac: "Command-L"}, exec: function(editor, line) { if (typeof line == "object") { var arg = this.name + " " + editor.getCursorPosition().row; editor.cmdLine.setValue(arg, 1); editor.cmdLine.focus(); return; } line = parseInt(line, 10); if (!isNaN(line)) editor.gotoLine(line); }, readOnly: true }, { name: "snippet", bindKey: {win: "Alt-C", mac: "Command-Alt-C"}, exec: function(editor, needle) { if (typeof needle == "object") { editor.cmdLine.setValue("snippet ", 1); editor.cmdLine.focus(); return; } var s = snippetManager.getSnippetByName(needle, editor); if (s) snippetManager.insertSnippet(editor, s.content); }, readOnly: true }, { name: "focusCommandLine", bindKey: "shift-esc|ctrl-`", exec: function(editor, needle) { editor.cmdLine.focus(); }, readOnly: true }, { name: "nextFile", bindKey: "Ctrl-tab", exec: function(editor) { doclist.cycleOpen(editor, 1); }, readOnly: true }, { name: "previousFile", bindKey: "Ctrl-shift-tab", exec: function(editor) { doclist.cycleOpen(editor, -1); }, readOnly: true }, { name: "execute", bindKey: "ctrl+enter", exec: function(editor) { try { var r = window.eval(editor.getCopyText() || editor.getValue()); } catch(e) { r = e; } editor.cmdLine.setValue(r + ""); }, readOnly: true }, { name: "showKeyboardShortcuts", bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"}, exec: function(editor) { config.loadModule("ace/ext/keybinding_menu", function(module) { module.init(editor); editor.showKeyboardShortcuts(); }); } }, { name: "increaseFontSize", bindKey: "Ctrl-+", exec: function(editor) { var size = parseInt(editor.getFontSize(), 10) || 12; editor.setFontSize(size + 1); } }, { name: "decreaseFontSize", bindKey: "Ctrl+-", exec: function(editor) { var size = parseInt(editor.getFontSize(), 10) || 12; editor.setFontSize(Math.max(size - 1 || 1)); } }, { name: "resetFontSize", bindKey: "Ctrl+0", exec: function(editor) { editor.setFontSize(12); } }]); env.editor.commands.addCommands(whitespace.commands); cmdLine.commands.bindKeys({ "Shift-Return|Ctrl-Return|Alt-Return": function(cmdLine) { cmdLine.insert("\n"); }, "Esc|Shift-Esc": function(cmdLine){ cmdLine.editor.focus(); }, "Return": function(cmdLine){ var command = cmdLine.getValue().split(/\s+/); var editor = cmdLine.editor; editor.commands.exec(command[0], editor, command[1]); editor.focus(); } }); cmdLine.commands.removeCommands(["find", "gotoline", "findall", "replace", "replaceall"]); var commands = env.editor.commands; commands.addCommand({ name: "save", bindKey: {win: "Ctrl-S", mac: "Command-S"}, exec: function(arg) { var session = env.editor.session; var name = session.name.match(/[^\/]+$/); localStorage.setItem( "saved_file:" + name, session.getValue() ); env.editor.cmdLine.setValue("saved "+ name); } }); commands.addCommand({ name: "load", bindKey: {win: "Ctrl-O", mac: "Command-O"}, exec: function(arg) { var session = env.editor.session; var name = session.name.match(/[^\/]+$/); var value = localStorage.getItem("saved_file:" + name); if (typeof value == "string") { session.setValue(value); env.editor.cmdLine.setValue("loaded "+ name); } else { env.editor.cmdLine.setValue("no previuos value saved for "+ name); } } }); var keybindings = { ace: null, // Null = use "default" keymapping vim: require("ace/keyboard/vim").handler, emacs: "ace/keyboard/emacs", custom: new HashHandler({ "gotoright": "Tab", "indent": "]", "outdent": "[", "gotolinestart": "^", "gotolineend": "$" }) }; var consoleHeight = 20; function onResize() { var left = env.split.$container.offsetLeft; var width = document.documentElement.clientWidth - left; container.style.width = width + "px"; container.style.height = document.documentElement.clientHeight - consoleHeight + "px"; env.split.resize(); consoleEl.style.width = width + "px"; cmdLine.resize(); } window.onresize = onResize; onResize(); var docEl = document.getElementById("doc"); var modeEl = document.getElementById("mode"); var wrapModeEl = document.getElementById("soft_wrap"); var themeEl = document.getElementById("theme"); var foldingEl = document.getElementById("folding"); var selectStyleEl = document.getElementById("select_style"); var highlightActiveEl = document.getElementById("highlight_active"); var showHiddenEl = document.getElementById("show_hidden"); var showGutterEl = document.getElementById("show_gutter"); var showPrintMarginEl = document.getElementById("show_print_margin"); var highlightSelectedWordE = document.getElementById("highlight_selected_word"); var showHScrollEl = document.getElementById("show_hscroll"); var showVScrollEl = document.getElementById("show_vscroll"); var animateScrollEl = document.getElementById("animate_scroll"); var softTabEl = document.getElementById("soft_tab"); var behavioursEl = document.getElementById("enable_behaviours"); fillDropdown(docEl, doclist.all); fillDropdown(modeEl, modelist.modes); var modesByName = modelist.modesByName; bindDropdown("mode", function(value) { env.editor.session.setMode(modesByName[value].mode || modesByName.text.mode); env.editor.session.modeName = value; }); doclist.history = doclist.docs.map(function(doc) { return doc.name; }); doclist.history.index = 0; doclist.cycleOpen = function(editor, dir) { var h = this.history; h.index += dir; if (h.index >= h.length) h.index = 0; else if (h.index <= 0) h.index = h.length - 1; var s = h[h.index]; docEl.value = s; docEl.onchange(); }; doclist.addToHistory = function(name) { var h = this.history; var i = h.indexOf(name); if (i != h.index) { if (i != -1) h.splice(i, 1); h.index = h.push(name); } }; bindDropdown("doc", function(name) { doclist.loadDoc(name, function(session) { if (!session) return; doclist.addToHistory(session.name); session = env.split.setSession(session); whitespace.detectIndentation(session); updateUIEditorOptions(); env.editor.focus(); }); }); function updateUIEditorOptions() { var editor = env.editor; var session = editor.session; session.setFoldStyle(foldingEl.value); saveOption(docEl, session.name); saveOption(modeEl, session.modeName || "text"); saveOption(wrapModeEl, session.getUseWrapMode() ? session.getWrapLimitRange().min || "free" : "off"); saveOption(selectStyleEl, editor.getSelectionStyle() == "line"); saveOption(themeEl, editor.getTheme()); saveOption(highlightActiveEl, editor.getHighlightActiveLine()); saveOption(showHiddenEl, editor.getShowInvisibles()); saveOption(showGutterEl, editor.renderer.getShowGutter()); saveOption(showPrintMarginEl, editor.renderer.getShowPrintMargin()); saveOption(highlightSelectedWordE, editor.getHighlightSelectedWord()); saveOption(showHScrollEl, editor.renderer.getHScrollBarAlwaysVisible()); saveOption(animateScrollEl, editor.getAnimatedScroll()); saveOption(softTabEl, session.getUseSoftTabs()); saveOption(behavioursEl, editor.getBehavioursEnabled()); } event.addListener(themeEl, "mouseover", function(e){ themeEl.desiredValue = e.target.value; if (!themeEl.$timer) themeEl.$timer = setTimeout(themeEl.updateTheme); }); event.addListener(themeEl, "mouseout", function(e){ themeEl.desiredValue = null; if (!themeEl.$timer) themeEl.$timer = setTimeout(themeEl.updateTheme, 20); }); themeEl.updateTheme = function(){ env.split.setTheme(themeEl.desiredValue || themeEl.selectedValue); themeEl.$timer = null; }; bindDropdown("theme", function(value) { if (!value) return; env.editor.setTheme(value); themeEl.selectedValue = value; }); bindDropdown("keybinding", function(value) { env.editor.setKeyboardHandler(keybindings[value]); }); bindDropdown("fontsize", function(value) { env.split.setFontSize(value); }); bindDropdown("folding", function(value) { env.editor.session.setFoldStyle(value); env.editor.setShowFoldWidgets(value !== "manual"); }); bindDropdown("soft_wrap", function(value) { var session = env.editor.session; var renderer = env.editor.renderer; switch (value) { case "off": session.setUseWrapMode(false); renderer.setPrintMarginColumn(80); break; case "free": session.setUseWrapMode(true); session.setWrapLimitRange(null, null); renderer.setPrintMarginColumn(80); break; default: session.setUseWrapMode(true); var col = parseInt(value, 10); session.setWrapLimitRange(col, col); renderer.setPrintMarginColumn(col); } }); bindCheckbox("select_style", function(checked) { env.editor.setSelectionStyle(checked ? "line" : "text"); }); bindCheckbox("highlight_active", function(checked) { env.editor.setHighlightActiveLine(checked); }); bindCheckbox("show_hidden", function(checked) { env.editor.setShowInvisibles(checked); }); bindCheckbox("display_indent_guides", function(checked) { env.editor.setDisplayIndentGuides(checked); }); bindCheckbox("show_gutter", function(checked) { env.editor.renderer.setShowGutter(checked); }); bindCheckbox("show_print_margin", function(checked) { env.editor.renderer.setShowPrintMargin(checked); }); bindCheckbox("highlight_selected_word", function(checked) { env.editor.setHighlightSelectedWord(checked); }); bindCheckbox("show_hscroll", function(checked) { env.editor.setOption("hScrollBarAlwaysVisible", checked); }); bindCheckbox("show_vscroll", function(checked) { env.editor.setOption("vScrollBarAlwaysVisible", checked); }); bindCheckbox("animate_scroll", function(checked) { env.editor.setAnimatedScroll(checked); }); bindCheckbox("soft_tab", function(checked) { env.editor.session.setUseSoftTabs(checked); }); bindCheckbox("enable_behaviours", function(checked) { env.editor.setBehavioursEnabled(checked); }); bindCheckbox("fade_fold_widgets", function(checked) { env.editor.setFadeFoldWidgets(checked); }); bindCheckbox("read_only", function(checked) { env.editor.setReadOnly(checked); }); bindCheckbox("scrollPastEnd", function(checked) { env.editor.setOption("scrollPastEnd", checked); }); bindDropdown("split", function(value) { var sp = env.split; if (value == "none") { sp.setSplits(1); } else { var newEditor = (sp.getSplits() == 1); sp.setOrientation(value == "below" ? sp.BELOW : sp.BESIDE); sp.setSplits(2); if (newEditor) { var session = sp.getEditor(0).session; var newSession = sp.setSession(session, 1); newSession.name = session.name; } } }); bindCheckbox("elastic_tabstops", function(checked) { env.editor.setOption("useElasticTabstops", checked); }); var iSearchCheckbox = bindCheckbox("isearch", function(checked) { env.editor.setOption("useIncrementalSearch", checked); }); env.editor.addEventListener('incrementalSearchSettingChanged', function(event) { iSearchCheckbox.checked = event.isEnabled; }); function synchroniseScrolling() { var s1 = env.split.$editors[0].session; var s2 = env.split.$editors[1].session; s1.on('changeScrollTop', function(pos) {s2.setScrollTop(pos)}); s2.on('changeScrollTop', function(pos) {s1.setScrollTop(pos)}); s1.on('changeScrollLeft', function(pos) {s2.setScrollLeft(pos)}); s2.on('changeScrollLeft', function(pos) {s1.setScrollLeft(pos)}); } bindCheckbox("highlight_token", function(checked) { var editor = env.editor; if (editor.tokenTooltip && !checked) { editor.tokenTooltip.destroy(); delete editor.tokenTooltip; } else if (checked) { editor.tokenTooltip = new TokenTooltip(editor); } }); var StatusBar = require("ace/ext/statusbar").StatusBar; new StatusBar(env.editor, cmdLine.container); var Emmet = require("ace/ext/emmet"); net.loadScript("http://nightwing.github.io/emmet-core/emmet.js", function() { Emmet.setCore(window.emmet); env.editor.setOption("enableEmmet", true); }); var snippetManager = require("ace/snippets").snippetManager; env.editSnippets = function() { var sp = env.split; if (sp.getSplits() == 2) { sp.setSplits(1); return; } sp.setSplits(1); sp.setSplits(2); sp.setOrientation(sp.BESIDE); var editor = sp.$editors[1]; var id = sp.$editors[0].session.$mode.$id || ""; var m = snippetManager.files[id]; if (!doclist["snippets/" + id]) { var text = m.snippetText; var s = doclist.initDoc(text, "", {}); s.setMode("ace/mode/snippets"); doclist["snippets/" + id] = s; } editor.on("blur", function() { m.snippetText = editor.getValue(); snippetManager.unregister(m.snippets); m.snippets = snippetManager.parseSnippetFile(m.snippetText, m.scope); snippetManager.register(m.snippets); }); sp.$editors[0].once("changeMode", function() { sp.setSplits(1); }); editor.setSession(doclist["snippets/" + id], 1); editor.focus(); }; require("ace/ext/language_tools"); env.editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true }); });define('ace/ext/spellcheck', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/editor', 'ace/config'], function(require, exports, module) { var event = require("../lib/event"); exports.contextMenuHandler = function(e){ var host = e.target; var text = host.textInput.getElement(); if (!host.selection.isEmpty()) return; var c = host.getCursorPosition(); var r = host.session.getWordRange(c.row, c.column); var w = host.session.getTextRange(r); host.session.tokenRe.lastIndex = 0; if (!host.session.tokenRe.test(w)) return; var PLACEHOLDER = "\x01\x01"; var value = w + " " + PLACEHOLDER; text.value = value; text.setSelectionRange(w.length, w.length + 1); text.setSelectionRange(0, 0); text.setSelectionRange(0, w.length); var afterKeydown = false; event.addListener(text, "keydown", function onKeydown() { event.removeListener(text, "keydown", onKeydown); afterKeydown = true; }); host.textInput.setInputHandler(function(newVal) { console.log(newVal , value, text.selectionStart, text.selectionEnd) if (newVal == value) return ''; if (newVal.lastIndexOf(value, 0) === 0) return newVal.slice(value.length); if (newVal.substr(text.selectionEnd) == value) return newVal.slice(0, -value.length); if (newVal.slice(-2) == PLACEHOLDER) { var val = newVal.slice(0, -2); if (val.slice(-1) == " ") { if (afterKeydown) return val.substring(0, text.selectionEnd); val = val.slice(0, -1); host.session.replace(r, val); return ""; } } return newVal; }); }; var Editor = require("../editor").Editor; require("../config").defineOptions(Editor.prototype, "editor", { spellcheck: { set: function(val) { var text = this.textInput.getElement(); text.spellcheck = !!val; if (!val) this.removeListener("nativecontextmenu", exports.contextMenuHandler); else this.on("nativecontextmenu", exports.contextMenuHandler); }, value: true } }); }); define('kitchen-sink/inline_editor', ['require', 'exports', 'module' , 'ace/line_widgets', 'ace/editor', 'ace/virtual_renderer', 'ace/lib/dom', 'ace/commands/default_commands'], function(require, exports, module) { var LineWidgets = require("ace/line_widgets").LineWidgets; var Editor = require("ace/editor").Editor; var Renderer = require("ace/virtual_renderer").VirtualRenderer; var dom = require("ace/lib/dom"); require("ace/commands/default_commands").commands.push({ name: "openInlineEditor", bindKey: "F3", exec: function(editor) { var split = window.env.split; var s = editor.session; var inlineEditor = new Editor(new Renderer()); var splitSession = split.$cloneSession(s); var row = editor.getCursorPosition().row; if (editor.session.lineWidgets && editor.session.lineWidgets[row]) { editor.session.lineWidgets[row].destroy(); return; } var rowCount = 10; var w = { row: row, fixedWidth: true, el: dom.createElement("div"), editor: editor }; var el = w.el; el.appendChild(inlineEditor.container); if (!editor.session.widgetManager) { editor.session.widgetManager = new LineWidgets(editor.session); editor.session.widgetManager.attach(editor); } var h = rowCount*editor.renderer.layerConfig.lineHeight; inlineEditor.container.style.height = h + "px"; el.style.position = "absolute"; el.style.zIndex = "4"; el.style.borderTop = "solid blue 2px"; el.style.borderBottom = "solid blue 2px"; inlineEditor.setSession(splitSession); editor.session.widgetManager.addLineWidget(w); var kb = { handleKeyboard:function(_,hashId, keyString) { if (hashId === 0 && keyString === "esc") { w.destroy(); return true; } } }; w.destroy = function() { editor.keyBinding.removeKeyboardHandler(kb); s.widgetManager.removeLineWidget(w); }; editor.keyBinding.addKeyboardHandler(kb); inlineEditor.keyBinding.addKeyboardHandler(kb); editor.on("changeSession", function(e) { w.el.parentNode && w.el.parentNode.removeChild(w.el); }); inlineEditor.setTheme("ace/theme/solarized_light"); } }); }); define('ace/line_widgets', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/range'], function(require, exports, module) { var oop = require("./lib/oop"); var dom = require("./lib/dom"); var Range = require("./range").Range; function LineWidgets(session) { this.session = session; this.session.widgetManager = this; this.session.getRowLength = this.getRowLength; this.session.$getWidgetScreenLength = this.$getWidgetScreenLength; this.updateOnChange = this.updateOnChange.bind(this); this.renderWidgets = this.renderWidgets.bind(this); this.measureWidgets = this.measureWidgets.bind(this); this.session._changedWidgets = []; this.detach = this.detach.bind(this); this.session.on("change", this.updateOnChange); }; (function() { this.getRowLength = function(row) { if (this.lineWidgets) var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0; else h = 0; if (!this.$useWrapMode || !this.$wrapData[row]) { return 1 + h; } else { return this.$wrapData[row].length + 1 + h; } }; this.$getWidgetScreenLength = function() { var screenRows = 0; this.lineWidgets.forEach(function(w){ if (w && w.rowCount) screenRows +=w.rowCount; }); return screenRows; }; this.attach = function(editor) { if (editor.widgetManager && editor.widgetManager != this) editor.widgetManager.detach(); if (this.editor == editor) return; this.detach(); this.editor = editor; this.editor.on("changeSession", this.detach); editor.widgetManager = this; editor.setOption("enableLineWidgets", true); editor.renderer.on("beforeRender", this.measureWidgets); editor.renderer.on("afterRender", this.renderWidgets); }; this.detach = function(e) { if (e && e.session == this.session) return; // sometimes attach can be called before setSession var editor = this.editor; if (!editor) return; editor.off("changeSession", this.detach); this.editor = null; editor.widgetManager = null; editor.renderer.off("beforeRender", this.measureWidgets); editor.renderer.off("afterRender", this.renderWidgets); this.session.lineWidgets.forEach(function(w) { if (w && w.el && w.el.parentNode) { w._inDocument = false; w.el.parentNode.removeChild(w.el); } }); }; this.updateOnChange = function(e) { var cells = this.session.lineWidgets; if (!cells) return; var delta = e.data; var range = delta.range; var startRow = range.start.row; var len = range.end.row - startRow; if (len === 0) { } else if (delta.action == "removeText" || delta.action == "removeLines") { var removed = cells.splice(startRow + 1, len); removed.forEach(function(w) { w && this.removeLineWidget(w); }, this); this.$updateRows(); } else { var args = Array(len); args.unshift(startRow, 0); cells.splice.apply(cells, args); this.$updateRows(); } }; this.$updateRows = function() { var lw = this.session.lineWidgets; if (!lw) return; var noWidgets = true; lw.forEach(function(w, i) { if (w) { noWidgets = false; w.row = i; } }); if (noWidgets) this.session.lineWidgets = null; } this.addLineWidget = function(w) { if (!this.session.lineWidgets) this.session.lineWidgets = Array(this.session.getLength()) this.session.lineWidgets[w.row] = w; var renderer = this.editor.renderer; if (w.html && !w.el) { w.el = dom.createElement("div"); w.el.innerHTML = w.html; } if (w.el) { dom.addCssClass(w.el, "ace_lineWidgetContainer"); renderer.container.appendChild(w.el); w._inDocument = true; } if (!w.coverGutter) { w.el.style.zIndex = 3; } if (!w.pixelHeight) { w.pixelHeight = w.el.offsetHeight; } if (w.rowCount == null) w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight; this.session._emit("changeFold", {data:{start:{row: w.row}}}); this.$updateRows(); this.renderWidgets(null, renderer); return w; }; this.removeLineWidget = function(w) { w._inDocument = false; if (w.el && w.el.parentNode) w.el.parentNode.removeChild(w.el); if (w.editor && w.editor.destroy) try { w.editor.destroy(); } catch(e){} this.session.lineWidgets[w.row] = undefined; this.session._emit("changeFold", {data:{start:{row: w.row}}}); this.$updateRows(); }; this.onWidgetChanged = function(w) { this.session._changedWidgets.push(w); this.editor && this.editor.renderer.updateFull(); }; this.measureWidgets = function(e, renderer) { var ws = this.session._changedWidgets; var config = renderer.layerConfig; if (!ws || !ws.length) return; var min = Infinity; for (var i = 0; i < ws.length; i++) { var w = ws[i].lineWidget; if (!w._inDocument) { w._inDocument = true; renderer.container.appendChild(w.el); } w.h = w.el.offsetHeight; if (!w.fixedWidth) { w.w = w.el.offsetWidth; w.screenWidth = Math.ceil(w.w / config.characterWidth); } var rowCount = w.h / config.lineHeight; if (w.coverLine) { rowCount -= this.session.getRowLineCount(w.row); if (rowCount < 0) rowCount = 0; } if (w.rowCount != rowCount) { w.rowCount = rowCount; if (w.row < min) min = w.row; } } if (min != Infinity) { this.session._emit("changeFold", {data:{start:{row: min}}}); this.session.lineWidgetWidth = null; } this.session._changedWidgets = []; }; this.renderWidgets = function(e, renderer) { var config = renderer.layerConfig; var ws = this.session.lineWidgets; if (!ws) return; var first = Math.min(this.firstRow, config.firstRow); var last = Math.max(this.lastRow, config.lastRow, ws.length); while (first > 0 && !ws[first]) first--; this.firstRow = config.firstRow; this.lastRow = config.lastRow; renderer.$cursorLayer.config = config; for (var i = first; i <= last; i++) { var w = ws[i]; if (!w || !w.el) continue; if (!w._inDocument) { w._inDocument = true; renderer.container.appendChild(w.el); } var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top; if (!w.coverLine) top += config.lineHeight * this.session.getRowLineCount(w.row); w.el.style.top = top - config.offset + "px"; var left = w.coverGutter ? 0 : renderer.gutterWidth; if (!w.fixedWidth) left -= renderer.scrollLeft; w.el.style.left = left + "px"; if (w.fixedWidth) { w.el.style.right = renderer.scrollBar.getWidth() + "px"; } else { w.el.style.right = ""; } } }; }).call(LineWidgets.prototype); exports.LineWidgets = LineWidgets; }); define('kitchen-sink/dev_util', ['require', 'exports', 'module' ], function(require, exports, module) { function isStrict() { try { return !arguments.callee.caller.caller.caller} catch(e){ return true } } function warn() { if (isStrict()) { console.error("trying to access to global variable"); } } function def(o, key, get) { Object.defineProperty(o, key, { configurable: true, get: get, set: function(val) { delete o[key]; o[key] = val; } }); } def(window, "ace", function(){ warn(); return window.env.editor }); def(window, "editor", function(){ warn(); return window.env.editor }); def(window, "session", function(){ warn(); return window.env.editor.session }); def(window, "split", function(){ warn(); return window.env.split }); }); define('kitchen-sink/file_drop', ['require', 'exports', 'module' , 'ace/config', 'ace/lib/event', 'ace/ext/modelist', 'ace/editor'], function(require, exports, module) { var config = require("ace/config"); var event = require("ace/lib/event"); var modelist = require("ace/ext/modelist"); module.exports = function(editor) { event.addListener(editor.container, "dragover", function(e) { var types = e.dataTransfer.types; if (types && Array.prototype.indexOf.call(types, 'Files') !== -1) return event.preventDefault(e); }); event.addListener(editor.container, "drop", function(e) { var file; try { file = e.dataTransfer.files[0]; if (window.FileReader) { var reader = new FileReader(); reader.onload = function() { var mode = modelist.getModeForPath(file.name); editor.session.doc.setValue(reader.result); editor.session.setMode(mode.mode); editor.session.modeName = mode.name; }; reader.readAsText(file); } return event.preventDefault(e); } catch(err) { return event.stopEvent(e); } }); }; var Editor = require("ace/editor").Editor; config.defineOptions(Editor.prototype, "editor", { loadDroppedFile: { set: function() { module.exports(this); }, value: true } }); });define('ace/ext/modelist', ['require', 'exports', 'module' ], function(require, exports, module) { var modes = []; function getModeForPath(path) { var mode = modesByName.text; var fileName = path.split(/[\/\\]/).pop(); for (var i = 0; i < modes.length; i++) { if (modes[i].supportsFile(fileName)) { mode = modes[i]; break; } } return mode; } var Mode = function(name, caption, extensions) { this.name = name; this.caption = caption; this.mode = "ace/mode/" + name; this.extensions = extensions; if (/\^/.test(extensions)) { var re = extensions.replace(/\|(\^)?/g, function(a, b){ return "$|" + (b ? "^" : "^.*\\."); }) + "$"; } else { var re = "^.*\\.(" + extensions + ")$"; } this.extRe = new RegExp(re, "gi"); }; Mode.prototype.supportsFile = function(filename) { return filename.match(this.extRe); }; var supportedModes = { ABAP: ["abap"], ActionScript:["as"], ADA: ["ada|adb"], AsciiDoc: ["asciidoc"], Assembly_x86:["asm"], AutoHotKey: ["ahk"], BatchFile: ["bat|cmd"], C9Search: ["c9search_results"], C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"], Clojure: ["clj"], Cobol: ["CBL|COB"], coffee: ["coffee|cf|cson|^Cakefile"], ColdFusion: ["cfm"], CSharp: ["cs"], CSS: ["css"], Curly: ["curly"], D: ["d|di"], Dart: ["dart"], Diff: ["diff|patch"], Dot: ["dot"], Erlang: ["erl|hrl"], EJS: ["ejs"], Forth: ["frt|fs|ldr"], FTL: ["ftl"], Glsl: ["glsl|frag|vert"], golang: ["go"], Groovy: ["groovy"], HAML: ["haml"], Handlebars: ["hbs|handlebars|tpl|mustache"], Haskell: ["hs"], haXe: ["hx"], HTML: ["html|htm|xhtml"], HTML_Ruby: ["erb|rhtml|html.erb"], INI: ["ini|conf|cfg|prefs"], Jack: ["jack"], Jade: ["jade"], Java: ["java"], JavaScript: ["js|jsm"], JSON: ["json"], JSONiq: ["jq"], JSP: ["jsp"], JSX: ["jsx"], Julia: ["jl"], LaTeX: ["tex|latex|ltx|bib"], LESS: ["less"], Liquid: ["liquid"], Lisp: ["lisp"], LiveScript: ["ls"], LogiQL: ["logic|lql"], LSL: ["lsl"], Lua: ["lua"], LuaPage: ["lp"], Lucene: ["lucene"], Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"], MATLAB: ["matlab"], Markdown: ["md|markdown"], MySQL: ["mysql"], MUSHCode: ["mc|mush"], Nix: ["nix"], ObjectiveC: ["m|mm"], OCaml: ["ml|mli"], Pascal: ["pas|p"], Perl: ["pl|pm"], pgSQL: ["pgsql"], PHP: ["php|phtml"], Powershell: ["ps1"], Prolog: ["plg|prolog"], Properties: ["properties"], Protobuf: ["proto"], Python: ["py"], R: ["r"], RDoc: ["Rd"], RHTML: ["Rhtml"], Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"], Rust: ["rs"], SASS: ["sass"], SCAD: ["scad"], Scala: ["scala"], Scheme: ["scm|rkt"], SCSS: ["scss"], SH: ["sh|bash|^.bashrc"], SJS: ["sjs"], Space: ["space"], snippets: ["snippets"], Soy_Template:["soy"], SQL: ["sql"], Stylus: ["styl|stylus"], SVG: ["svg"], Tcl: ["tcl"], Tex: ["tex"], Text: ["txt"], Textile: ["textile"], Toml: ["toml"], Twig: ["twig"], Typescript: ["ts|typescript|str"], VBScript: ["vbs"], Velocity: ["vm"], Verilog: ["v|vh|sv|svh"], XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"], XQuery: ["xq"], YAML: ["yaml|yml"] }; var nameOverrides = { ObjectiveC: "Objective-C", CSharp: "C#", golang: "Go", C_Cpp: "C/C++", coffee: "CoffeeScript", HTML_Ruby: "HTML (Ruby)", FTL: "FreeMarker" }; var modesByName = {}; for (var name in supportedModes) { var data = supportedModes[name]; var displayName = nameOverrides[name] || name; var filename = name.toLowerCase(); var mode = new Mode(filename, displayName, data[0]); modesByName[filename] = mode; modes.push(mode); } module.exports = { getModeForPath: getModeForPath, modes: modes, modesByName: modesByName }; }); define('ace/theme/textmate', ['require', 'exports', 'module' , 'ace/lib/dom'], function(require, exports, module) { exports.isDark = false; exports.cssClass = "ace-tm"; exports.cssText = ".ace-tm .ace_gutter {\ background: #f0f0f0;\ color: #333;\ }\ .ace-tm .ace_print-margin {\ width: 1px;\ background: #e8e8e8;\ }\ .ace-tm .ace_fold {\ background-color: #6B72E6;\ }\ .ace-tm {\ background-color: #FFFFFF;\ }\ .ace-tm .ace_cursor {\ color: black;\ }\ .ace-tm .ace_invisible {\ color: rgb(191, 191, 191);\ }\ .ace-tm .ace_storage,\ .ace-tm .ace_keyword {\ color: blue;\ }\ .ace-tm .ace_constant {\ color: rgb(197, 6, 11);\ }\ .ace-tm .ace_constant.ace_buildin {\ color: rgb(88, 72, 246);\ }\ .ace-tm .ace_constant.ace_language {\ color: rgb(88, 92, 246);\ }\ .ace-tm .ace_constant.ace_library {\ color: rgb(6, 150, 14);\ }\ .ace-tm .ace_invalid {\ background-color: rgba(255, 0, 0, 0.1);\ color: red;\ }\ .ace-tm .ace_support.ace_function {\ color: rgb(60, 76, 114);\ }\ .ace-tm .ace_support.ace_constant {\ color: rgb(6, 150, 14);\ }\ .ace-tm .ace_support.ace_type,\ .ace-tm .ace_support.ace_class {\ color: rgb(109, 121, 222);\ }\ .ace-tm .ace_keyword.ace_operator {\ color: rgb(104, 118, 135);\ }\ .ace-tm .ace_string {\ color: rgb(3, 106, 7);\ }\ .ace-tm .ace_comment {\ color: rgb(76, 136, 107);\ }\ .ace-tm .ace_comment.ace_doc {\ color: rgb(0, 102, 255);\ }\ .ace-tm .ace_comment.ace_doc.ace_tag {\ color: rgb(128, 159, 191);\ }\ .ace-tm .ace_constant.ace_numeric {\ color: rgb(0, 0, 205);\ }\ .ace-tm .ace_variable {\ color: rgb(49, 132, 149);\ }\ .ace-tm .ace_xml-pe {\ color: rgb(104, 104, 91);\ }\ .ace-tm .ace_entity.ace_name.ace_function {\ color: #0000A2;\ }\ .ace-tm .ace_heading {\ color: rgb(12, 7, 255);\ }\ .ace-tm .ace_list {\ color:rgb(185, 6, 144);\ }\ .ace-tm .ace_meta.ace_tag {\ color:rgb(0, 22, 142);\ }\ .ace-tm .ace_string.ace_regex {\ color: rgb(255, 0, 0)\ }\ .ace-tm .ace_marker-layer .ace_selection {\ background: rgb(181, 213, 255);\ }\ .ace-tm.ace_multiselect .ace_selection.ace_start {\ box-shadow: 0 0 3px 0px white;\ border-radius: 2px;\ }\ .ace-tm .ace_marker-layer .ace_step {\ background: rgb(252, 255, 0);\ }\ .ace-tm .ace_marker-layer .ace_stack {\ background: rgb(164, 229, 101);\ }\ .ace-tm .ace_marker-layer .ace_bracket {\ margin: -1px 0 0 -1px;\ border: 1px solid rgb(192, 192, 192);\ }\ .ace-tm .ace_marker-layer .ace_active-line {\ background: rgba(0, 0, 0, 0.07);\ }\ .ace-tm .ace_gutter-active-line {\ background-color : #dcdcdc;\ }\ .ace-tm .ace_marker-layer .ace_selected-word {\ background: rgb(250, 250, 255);\ border: 1px solid rgb(200, 200, 250);\ }\ .ace-tm .ace_indent-guide {\ background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\ }\ "; var dom = require("../lib/dom"); dom.importCssString(exports.cssText, exports.cssClass); }); define('ace/ext/whitespace', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) { var lang = require("../lib/lang"); exports.$detectIndentation = function(lines, fallback) { var stats = []; var changes = []; var tabIndents = 0; var prevSpaces = 0; var max = Math.min(lines.length, 1000); for (var i = 0; i < max; i++) { var line = lines[i]; if (!/^\s*[^*+\-\s]/.test(line)) continue; var tabs = line.match(/^\t*/)[0].length; if (line[0] == "\t") tabIndents++; var spaces = line.match(/^ */)[0].length; if (spaces && line[spaces] != "\t") { var diff = spaces - prevSpaces; if (diff > 0 && !(prevSpaces%diff) && !(spaces%diff)) changes[diff] = (changes[diff] || 0) + 1; stats[spaces] = (stats[spaces] || 0) + 1; } prevSpaces = spaces; while (line[line.length - 1] == "\\") line = lines[i++]; } function getScore(indent) { var score = 0; for (var i = indent; i < stats.length; i += indent) score += stats[i] || 0; return score; } var changesTotal = changes.reduce(function(a,b){return a+b}, 0); var first = {score: 0, length: 0}; var spaceIndents = 0; for (var i = 1; i < 12; i++) { if (i == 1) { spaceIndents = getScore(i); var score = 1; } else var score = getScore(i) / spaceIndents; if (changes[i]) { score += changes[i] / changesTotal; } if (score > first.score) first = {score: score, length: i}; } if (first.score && first.score > 1.4) var tabLength = first.length; if (tabIndents > spaceIndents + 1) return {ch: "\t", length: tabLength}; if (spaceIndents + 1 > tabIndents) return {ch: " ", length: tabLength}; }; exports.detectIndentation = function(session) { var lines = session.getLines(0, 1000); var indent = exports.$detectIndentation(lines) || {}; if (indent.ch) session.setUseSoftTabs(indent.ch == " "); if (indent.length) session.setTabSize(indent.length); return indent; }; exports.trimTrailingSpace = function(session, trimEmpty) { var doc = session.getDocument(); var lines = doc.getAllLines(); var min = trimEmpty ? -1 : 0; for (var i = 0, l=lines.length; i < l; i++) { var line = lines[i]; var index = line.search(/\s+$/); if (index > min) doc.removeInLine(i, index, line.length); } }; exports.convertIndentation = function(session, ch, len) { var oldCh = session.getTabString()[0]; var oldLen = session.getTabSize(); if (!len) len = oldLen; if (!ch) ch = oldCh; var tab = ch == "\t" ? ch: lang.stringRepeat(ch, len); var doc = session.doc; var lines = doc.getAllLines(); var cache = {}; var spaceCache = {}; for (var i = 0, l=lines.length; i < l; i++) { var line = lines[i]; var match = line.match(/^\s*/)[0]; if (match) { var w = session.$getStringScreenWidth(match)[0]; var tabCount = Math.floor(w/oldLen); var reminder = w%oldLen; var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount)); toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder)); if (toInsert != match) { doc.removeInLine(i, 0, match.length); doc.insertInLine({row: i, column: 0}, toInsert); } } } session.setTabSize(len); session.setUseSoftTabs(ch == " "); }; exports.$parseStringArg = function(text) { var indent = {}; if (/t/.test(text)) indent.ch = "\t"; else if (/s/.test(text)) indent.ch = " "; var m = text.match(/\d+/); if (m) indent.length = parseInt(m[0], 10); return indent; }; exports.$parseArg = function(arg) { if (!arg) return {}; if (typeof arg == "string") return exports.$parseStringArg(arg); if (typeof arg.text == "string") return exports.$parseStringArg(arg.text); return arg; }; exports.commands = [{ name: "detectIndentation", exec: function(editor) { exports.detectIndentation(editor.session); } }, { name: "trimTrailingSpace", exec: function(editor) { exports.trimTrailingSpace(editor.session); } }, { name: "convertIndentation", exec: function(editor, arg) { var indent = exports.$parseArg(arg); exports.convertIndentation(editor.session, indent.ch, indent.length); } }, { name: "setIndentation", exec: function(editor, arg) { var indent = exports.$parseArg(arg); indent.length && editor.session.setTabSize(indent.length); indent.ch && editor.session.setUseSoftTabs(indent.ch == " "); } }]; }); define('kitchen-sink/doclist', ['require', 'exports', 'module' , 'ace/edit_session', 'ace/undomanager', 'ace/lib/net', 'ace/ext/modelist'], function(require, exports, module) { var EditSession = require("ace/edit_session").EditSession; var UndoManager = require("ace/undomanager").UndoManager; var net = require("ace/lib/net"); var modelist = require("ace/ext/modelist"); var fileCache = {}; function initDoc(file, path, doc) { if (doc.prepare) file = doc.prepare(file); var session = new EditSession(file); session.setUndoManager(new UndoManager()); doc.session = session; doc.path = path; session.name = doc.name; if (doc.wrapped) { session.setUseWrapMode(true); session.setWrapLimitRange(80, 80); } var mode = modelist.getModeForPath(path); session.modeName = mode.name; session.setMode(mode.mode); return session; } function makeHuge(txt) { for (var i = 0; i < 5; i++) txt += txt; return txt; } var docs = { "docs/javascript.js": {order: 1, name: "JavaScript"}, "docs/latex.tex": {name: "LaTeX", wrapped: true}, "docs/markdown.md": {name: "Markdown", wrapped: true}, "docs/mushcode.mc": {name: "MUSHCode", wrapped: true}, "docs/pgsql.pgsql": {name: "pgSQL", wrapped: true}, "docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true}, "docs/sql.sql": {name: "SQL", wrapped: true}, "docs/textile.textile": {name: "Textile", wrapped: true}, "docs/c9search.c9search_results": "C9 Search Results", "docs/Nix.nix": "Nix" }; var ownSource = { }; var hugeDocs = { "src/ace.js": "", "src-min/ace.js": "" }; modelist.modes.forEach(function(m) { var ext = m.extensions.split("|")[0]; if (ext[0] === "^") { path = ext.substr(1); } else { var path = m.name + "." + ext; } path = "docs/" + path; if (!docs[path]) { docs[path] = {name: m.caption}; } else if (typeof docs[path] == "object" && !docs[path].name) { docs[path].name = m.caption; } }); if (window.require && window.require.s) try { for (var path in window.require.s.contexts._.defined) { if (path.indexOf("!") != -1) path = path.split("!").pop(); else path = path + ".js"; ownSource[path] = ""; } } catch(e) {} function sort(list) { return list.sort(function(a, b) { var cmp = (b.order || 0) - (a.order || 0); return cmp || a.name && a.name.localeCompare(b.name); }); } function prepareDocList(docs) { var list = []; for (var path in docs) { var doc = docs[path]; if (typeof doc != "object") doc = {name: doc || path}; doc.path = path; doc.desc = doc.name.replace(/^(ace|docs|demo|build)\//, ""); if (doc.desc.length > 18) doc.desc = doc.desc.slice(0, 7) + ".." + doc.desc.slice(-9); fileCache[doc.name] = doc; list.push(doc); } return list; } function loadDoc(name, callback) { var doc = fileCache[name]; if (!doc) return callback(null); if (doc.session) return callback(doc.session); var path = doc.path; var parts = path.