Conflicts:
	.gitmodules
	Makefile.dryice.js
	demo/demo.js
	demo/kitchen-sink/boot.js
	kitchen-sink.html
	lib/ace/commands/default_commands.js
	lib/ace/test/tests.html
	package.json
	support/pilot
This commit is contained in:
Fabian Jakobs 2011-11-02 13:25:32 +01:00
commit 62a3b4edf5
18 changed files with 704 additions and 808 deletions

7
.gitmodules vendored
View file

@ -5,8 +5,5 @@
path = node_modules/dryice
url = git://github.com/ajaxorg/dryice.git
[submodule "node_modules/pilot"]
path = node_modules/pilot
url = git://github.com/ajaxorg/pilot.git
[submodule "node_modules/cockpit"]
path = node_modules/cockpit
url = git://github.com/ajaxorg/cockpit.git
path = node_modules/pilot
url = git://github.com/ajaxorg/pilot.git

View file

@ -297,7 +297,7 @@ console.log('# ace worker ---------');
aceHome + "/lib/ace/worker/worker.js",
worker
],
filter: [ copy.filter.uglifyjs, filterTextPlugin ],
filter: [ filterTextPlugin, copy.filter.uglifyjs ],
dest: "build/src/worker-" + mode + ".js"
});
});
@ -349,7 +349,7 @@ function demo() {
source: [
copy.source.commonjs({
project: project,
require: [ "pilot/index", "ace/defaults", "demo/kitchen-sink/boot" ]
require: [ "demo/kitchen-sink/demo" ]
})
],
filter: [ copy.filter.moduleDefines ],

View file

@ -41,8 +41,6 @@
var require = window.__ace_shadowed__.require;
require("pilot/index");
var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins([ "pilot/index" ]);
var Dom = require("pilot/dom");
var Event = require("pilot/event");
@ -53,9 +51,6 @@ var EditSession = require("ace/edit_session").EditSession;
var UndoManager = require("ace/undomanager").UndoManager;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins([ "pilot/index" ]);
window.__ace_shadowed__.edit = function(el) {
if (typeof(el) == "string") {
el = document.getElementById(el);
@ -68,16 +63,14 @@ window.__ace_shadowed__.edit = function(el) {
var editor = new Editor(new Renderer(el, "ace/theme/textmate"));
editor.setSession(doc);
var env = require("pilot/environment").create();
catalog.startupPlugins({ env: env }).then(function() {
env.document = doc;
env.editor = env;
var env = {};
env.document = doc;
env.editor = env;
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
});
el.env = env;
});
el.env = env;
return editor;
}

View file

@ -1,57 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Skywriter.
*
* The Initial Developer of the Original Code is
* Mozilla.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Kevin Dangoor (kdangoor@mozilla.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
require("pilot/fixoldbrowsers");
require("pilot/plugin_manager");
require("pilot/environment");
require("demo/kitchen-sink/demo");
require("pilot/index");
require("ace/defaults");
var plugins = [ "pilot/index"];
var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins(plugins).then(function() {
var env = require("pilot/environment").create();
catalog.startupPlugins({ env: env }).then(function() {
require("demo/kitchen-sink/demo").launch(env);
});
});
});

View file

@ -40,8 +40,10 @@
define(function(require, exports, module) {
require("pilot/fixoldbrowsers");
var env = {};
var net = require("ace/lib/net");
var canon = require("pilot/canon");
var event = require("pilot/event");
var Range = require("ace/range").Range;
var Editor = require("ace/editor").Editor;
@ -86,470 +88,6 @@ Mode.prototype.supportsFile = function(filename) {
return filename.match(this.extRe);
};
exports.launch = function(env) {
var modes = [
new Mode("c_cpp", "C/C++", require("ace/mode/c_cpp").Mode, ["c", "cpp", "cxx", "h", "hpp"]),
new Mode("clojure", "Clojure", require("ace/mode/clojure").Mode, ["clj"]),
new Mode("coffee", "CoffeeScript", require("ace/mode/coffee").Mode, ["coffee"]),
new Mode("coldfusion", "ColdFusion", require("ace/mode/coldfusion").Mode, ["cfm"]),
new Mode("csharp", "C#", require("ace/mode/csharp").Mode, ["cs"]),
new Mode("css", "CSS", require("ace/mode/css").Mode, ["css"]),
new Mode("groovy", "Groovy", require("ace/mode/groovy").Mode, ["groovy"]),
new Mode("html", "HTML", require("ace/mode/html").Mode, ["html", "htm"]),
new Mode("java", "Java", require("ace/mode/java").Mode, ["java"]),
new Mode("javascript", "JavaScript", require("ace/mode/javascript").Mode, ["js"]),
new Mode("json", "JSON", require("ace/mode/json").Mode, ["json"]),
new Mode("latex", "LaTeX", require("ace/mode/latex").Mode, ["tex"]),
new Mode("lua", "Lua", require("ace/mode/lua").Mode, ["lua"]),
new Mode("markdown", "MarkDown", require("ace/mode/markdown").Mode, ["md", "markdown"]),
new Mode("ocaml", "OCaml", require("ace/mode/ocaml").Mode, ["ml", "mli"]),
new Mode("perl", "Perl", require("ace/mode/perl").Mode, ["pl", "pm"]),
new Mode("php", "PHP",require("ace/mode/php").Mode, ["php"]),
new Mode("powershell", "Powershell", require("ace/mode/powershell").Mode, ["ps1"]),
new Mode("python", "Python", require("ace/mode/python").Mode, ["py"]),
new Mode("scala", "Scala", require("ace/mode/scala").Mode, ["scala"]),
new Mode("scss", "SCSS", require("ace/mode/scss").Mode, ["scss"]),
new Mode("ruby", "Ruby", require("ace/mode/ruby").Mode, ["rb"]),
new Mode("sql", "SQL", require("ace/mode/sql").Mode, ["sql"]),
new Mode("svg", "SVG", require("ace/mode/SVG").Mode, ["svg"]),
new Mode("text", "Text", require("ace/mode/text").Mode, ["txt"]),
new Mode("textile", "Textile", require("ace/mode/textile").Mode, ["textile"]),
new Mode("xml", "XML", require("ace/mode/xml").Mode, ["xml"])
];
modesByName = {};
modes.forEach(function(m) {
modesByName[m.name] = m;
});
var loreIpsum = require("ace/requirejs/text!demo/kitchen-sink/docs/plaintext.txt");
for (var i = 0; i < 5; i++) {
loreIpsum += loreIpsum;
}
var docs = [
new Doc(
"javascript", "JavaScript",
require("ace/requirejs/text!demo/kitchen-sink/docs/javascript.js")
),
new WrappedDoc("text", "Plain Text", loreIpsum),
new Doc(
"coffee", "Coffeescript",
require("ace/requirejs/text!demo/kitchen-sink/docs/coffeescript.coffee")
),
new Doc(
"json", "JSON",
require("ace/requirejs/text!demo/kitchen-sink/docs/json.json")
),
new Doc(
"css", "CSS",
require("ace/requirejs/text!demo/kitchen-sink/docs/css.css")
),
new Doc(
"scss", "SCSS",
require("ace/requirejs/text!demo/kitchen-sink/docs/scss.scss")
),
new Doc(
"html", "HTML",
require("ace/requirejs/text!demo/kitchen-sink/docs/html.html")
),
new Doc(
"xml", "XML",
require("ace/requirejs/text!demo/kitchen-sink/docs/xml.xml")
),
new Doc(
"svg", "SVG",
require("ace/requirejs/text!demo/kitchen-sink/docs/svg.svg")
),
new Doc(
"php", "PHP",
require("ace/requirejs/text!demo/kitchen-sink/docs/php.php")
),
new Doc(
"coldfusion", "ColdFusion",
require("ace/requirejs/text!demo/kitchen-sink/docs/coldfusion.cfm")
),
new Doc(
"python", "Python",
require("ace/requirejs/text!demo/kitchen-sink/docs/python.py")
),
new Doc(
"ruby", "Ruby",
require("ace/requirejs/text!demo/kitchen-sink/docs/ruby.rb")
),
new Doc(
"perl", "Perl",
require("ace/requirejs/text!demo/kitchen-sink/docs/perl.pl")
),
new Doc(
"ocaml", "OCaml",
require("ace/requirejs/text!demo/kitchen-sink/docs/ocaml.ml")
),
new Doc(
"lua", "Lua",
require("ace/requirejs/text!demo/kitchen-sink/docs/lua.lua")
),
new Doc(
"java", "Java",
require("ace/requirejs/text!demo/kitchen-sink/docs/java.java")
),
new Doc(
"clojure", "Clojure",
require("ace/requirejs/text!demo/kitchen-sink/docs/clojure.clj")
),
new Doc(
"groovy", "Groovy",
require("ace/requirejs/text!demo/kitchen-sink/docs/groovy.groovy")
),
new Doc(
"scala", "Scala",
require("ace/requirejs/text!demo/kitchen-sink/docs/scala.scala")
),
new Doc(
"csharp", "C#",
require("ace/requirejs/text!demo/kitchen-sink/docs/csharp.cs")
),
new Doc(
"powershell", "Powershell",
require("ace/requirejs/text!demo/kitchen-sink/docs/powershell.ps1")
),
new Doc(
"c_cpp", "C/C++",
require("ace/requirejs/text!demo/kitchen-sink/docs/cpp.cpp")
),
new Doc(
"markdown", "Markdown",
require("ace/requirejs/text!demo/kitchen-sink/docs/markdown.md")
),
new WrappedDoc(
"markdown", "Markdown",
require("ace/requirejs/text!demo/kitchen-sink/docs/markdown.md")
),
new WrappedDoc(
"textile", "Textile",
require("ace/requirejs/text!demo/kitchen-sink/docs/textile.textile")
),
new WrappedDoc(
"latex", "LaTeX",
require("ace/requirejs/text!demo/kitchen-sink/docs/latex.tex")
)
];
var docsByName = {};
docs.forEach(function(d) {
docsByName[d.name] = d;
});
var keybindings = {
// Null = use "default" keymapping
ace: null,
vim: vim,
emacs: emacs,
// This is a way to define simple keyboard remappings
custom: new HashHandler({
"gotoright": "Tab",
"indent": "]",
"outdent": "[",
"gotolinestart": "^",
"gotolineend": "$"
})
};
var container = document.getElementById("editor");
var cockpitInput = document.getElementById("cockpitInput");
// Splitting.
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;
window.ace = env.editor;
var docEl = document.getElementById("doc");
var modeEl = document.getElementById("mode");
var wrapModeEl = document.getElementById("soft_wrap");
var themeEl = document.getElementById("theme");
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 softTabEl = document.getElementById("soft_tab");
var behavioursEl = document.getElementById("enable_behaviours");
docs.forEach(function(doc) {
var option = document.createElement("option");
option.setAttribute("value", doc.name);
option.innerHTML = doc.desc;
docEl.appendChild(option);
});
modes.forEach(function(mode) {
var option = document.createElement("option");
option.setAttribute("value", mode.name);
option.innerHTML = mode.desc;
modeEl.appendChild(option);
});
bindDropdown("doc", function(value) {
var doc = docsByName[value].doc;
var session = env.split.setSession(doc);
session.name = doc.name;
updateUIEditorOptions();
env.editor.focus();
});
function updateUIEditorOptions() {
var editor = env.editor;
var session = editor.session;
docEl.value = session.name;
modeEl.value = session.getMode().name || "text";
if (!session.getUseWrapMode()) {
wrapModeEl.value = "off";
} else {
wrapModeEl.value = session.getWrapLimitRange().min || "free";
}
selectStyleEl.checked = editor.getSelectionStyle() == "line";
themeEl.value = editor.getTheme();
highlightActiveEl.checked = editor.getHighlightActiveLine();
showHiddenEl.checked = editor.getShowInvisibles();
showGutterEl.checked = editor.renderer.getShowGutter();
showPrintMarginEl.checked = editor.renderer.getShowPrintMargin();
highlightSelectedWordE.checked = editor.getHighlightSelectedWord();
showHScrollEl.checked = editor.renderer.getHScrollBarAlwaysVisible();
softTabEl.checked = session.getUseSoftTabs();
behavioursEl.checked = editor.getBehavioursEnabled();
}
bindDropdown("mode", function(value) {
env.editor.getSession().setMode(modesByName[value].mode || modesByName.text.mode);
});
bindDropdown("theme", function(value) {
if (require.packaged) {
loadTheme(value, function() {
env.editor.setTheme(value);
});
}
else {
env.editor.setTheme(value);
}
});
bindDropdown("keybinding", function(value) {
env.editor.setKeyboardHandler(keybindings[value]);
});
bindDropdown("fontsize", function(value) {
env.split.setFontSize(value);
});
bindDropdown("soft_wrap", function(value) {
var session = env.editor.getSession();
var renderer = env.editor.renderer;
switch (value) {
case "off":
session.setUseWrapMode(false);
renderer.setPrintMarginColumn(80);
break;
case "40":
session.setUseWrapMode(true);
session.setWrapLimitRange(40, 40);
renderer.setPrintMarginColumn(40);
break;
case "80":
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
renderer.setPrintMarginColumn(80);
break;
case "free":
session.setUseWrapMode(true);
session.setWrapLimitRange(null, null);
renderer.setPrintMarginColumn(80);
break;
}
});
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("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.renderer.setHScrollBarAlwaysVisible(checked);
});
bindCheckbox("soft_tab", function(checked) {
env.editor.getSession().setUseSoftTabs(checked);
});
bindCheckbox("enable_behaviours", function(checked) {
env.editor.setBehavioursEnabled(checked);
});
var secondSession = null;
bindDropdown("split", function(value) {
var sp = env.split;
if (value == "none") {
if (sp.getSplits() == 2) {
secondSession = sp.getEditor(1).session;
}
sp.setSplits(1);
} else {
var newEditor = (sp.getSplits() == 1);
if (value == "below") {
sp.setOriantation(sp.BELOW);
} else {
sp.setOriantation(sp.BESIDE);
}
sp.setSplits(2);
if (newEditor) {
var session = secondSession || sp.getEditor(0).session;
var newSession = sp.setSession(session, 1);
newSession.name = session.name;
}
}
});
function bindCheckbox(id, callback) {
var el = document.getElementById(id);
var onCheck = function() {
callback(!!el.checked);
};
el.onclick = onCheck;
onCheck();
}
function bindDropdown(id, callback) {
var el = document.getElementById(id);
var onChange = function() {
callback(el.value);
};
el.onchange = onChange;
onChange();
}
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 + "px";
env.split.resize();
// env.editor.resize();
}
window.onresize = onResize;
env.editor.renderer.onResize(true);
event.addListener(container, "dragover", function(e) {
return event.preventDefault(e);
});
event.addListener(container, "drop", function(e) {
var file;
try {
file = e.dataTransfer.files[0];
} catch(err) {
return event.stopEvent();
}
if (window.FileReader) {
var reader = new FileReader();
reader.onload = function(e) {
env.editor.getSelection().selectAll();
var mode = modesByName.text;
for (var i = 0; i < modes.length; i++) {
if (modes[i].supportsFile(file.name)) {
mode = modes[i];
break;
}
}
env.editor.onTextInput(reader.result);
modeEl.value = mode.name;
env.editor.getSession().setMode(mode.mode);
};
reader.readAsText(file);
}
return event.preventDefault(e);
});
/**
* This demonstrates how you can define commands and bind shortcuts to them.
*/
// Fake-Save, works from the editor and the command line.
canon.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor"
},
exec: function() {
alert("Fake Save File");
}
});
// Fake-Print with custom lookup-sender-match function.
canon.addCommand({
name: "print",
bindKey: {
win: "Ctrl-P",
mac: "Command-P",
sender: function(env, sender, hashId, keyString) {
if (sender == "editor") {
return true;
} else {
alert("Sorry, can only print from the editor");
}
}
},
exec: function() {
alert("Fake Print File");
}
});
};
var themes = {};
function loadTheme(name, callback) {
if (themes[name])
@ -561,4 +99,463 @@ function loadTheme(name, callback) {
net.loadScript(fileName, callback);
}
var modes = [
new Mode("c_cpp", "C/C++", require("ace/mode/c_cpp").Mode, ["c", "cpp", "cxx", "h", "hpp"]),
new Mode("clojure", "Clojure", require("ace/mode/clojure").Mode, ["clj"]),
new Mode("coffee", "CoffeeScript", require("ace/mode/coffee").Mode, ["coffee"]),
new Mode("coldfusion", "ColdFusion", require("ace/mode/coldfusion").Mode, ["cfm"]),
new Mode("csharp", "C#", require("ace/mode/csharp").Mode, ["cs"]),
new Mode("css", "CSS", require("ace/mode/css").Mode, ["css"]),
new Mode("groovy", "Groovy", require("ace/mode/groovy").Mode, ["groovy"]),
new Mode("html", "HTML", require("ace/mode/html").Mode, ["html", "htm"]),
new Mode("java", "Java", require("ace/mode/java").Mode, ["java"]),
new Mode("javascript", "JavaScript", require("ace/mode/javascript").Mode, ["js"]),
new Mode("json", "JSON", require("ace/mode/json").Mode, ["json"]),
new Mode("latex", "LaTeX", require("ace/mode/latex").Mode, ["tex"]),
new Mode("lua", "Lua", require("ace/mode/lua").Mode, ["lua"]),
new Mode("markdown", "MarkDown", require("ace/mode/markdown").Mode, ["md", "markdown"]),
new Mode("ocaml", "OCaml", require("ace/mode/ocaml").Mode, ["ml", "mli"]),
new Mode("perl", "Perl", require("ace/mode/perl").Mode, ["pl", "pm"]),
new Mode("php", "PHP",require("ace/mode/php").Mode, ["php"]),
new Mode("powershell", "Powershell", require("ace/mode/powershell").Mode, ["ps1"]),
new Mode("python", "Python", require("ace/mode/python").Mode, ["py"]),
new Mode("scala", "Scala", require("ace/mode/scala").Mode, ["scala"]),
new Mode("scss", "SCSS", require("ace/mode/scss").Mode, ["scss"]),
new Mode("ruby", "Ruby", require("ace/mode/ruby").Mode, ["rb"]),
new Mode("sql", "SQL", require("ace/mode/sql").Mode, ["sql"]),
new Mode("svg", "SVG", require("ace/mode/SVG").Mode, ["svg"]),
new Mode("text", "Text", require("ace/mode/text").Mode, ["txt"]),
new Mode("textile", "Textile", require("ace/mode/textile").Mode, ["textile"]),
new Mode("xml", "XML", require("ace/mode/xml").Mode, ["xml"])
];
modesByName = {};
modes.forEach(function(m) {
modesByName[m.name] = m;
});
var loreIpsum = require("ace/requirejs/text!demo/kitchen-sink/docs/plaintext.txt");
for (var i = 0; i < 5; i++) {
loreIpsum += loreIpsum;
}
var docs = [
new Doc(
"javascript", "JavaScript",
require("ace/requirejs/text!demo/kitchen-sink/docs/javascript.js")
),
new WrappedDoc("text", "Plain Text", loreIpsum),
new Doc(
"coffee", "Coffeescript",
require("ace/requirejs/text!demo/kitchen-sink/docs/coffeescript.coffee")
),
new Doc(
"json", "JSON",
require("ace/requirejs/text!demo/kitchen-sink/docs/json.json")
),
new Doc(
"css", "CSS",
require("ace/requirejs/text!demo/kitchen-sink/docs/css.css")
),
new Doc(
"scss", "SCSS",
require("ace/requirejs/text!demo/kitchen-sink/docs/scss.scss")
),
new Doc(
"html", "HTML",
require("ace/requirejs/text!demo/kitchen-sink/docs/html.html")
),
new Doc(
"xml", "XML",
require("ace/requirejs/text!demo/kitchen-sink/docs/xml.xml")
),
new Doc(
"svg", "SVG",
require("ace/requirejs/text!demo/kitchen-sink/docs/svg.svg")
),
new Doc(
"php", "PHP",
require("ace/requirejs/text!demo/kitchen-sink/docs/php.php")
),
new Doc(
"coldfusion", "ColdFusion",
require("ace/requirejs/text!demo/kitchen-sink/docs/coldfusion.cfm")
),
new Doc(
"python", "Python",
require("ace/requirejs/text!demo/kitchen-sink/docs/python.py")
),
new Doc(
"ruby", "Ruby",
require("ace/requirejs/text!demo/kitchen-sink/docs/ruby.rb")
),
new Doc(
"perl", "Perl",
require("ace/requirejs/text!demo/kitchen-sink/docs/perl.pl")
),
new Doc(
"ocaml", "OCaml",
require("ace/requirejs/text!demo/kitchen-sink/docs/ocaml.ml")
),
new Doc(
"lua", "Lua",
require("ace/requirejs/text!demo/kitchen-sink/docs/lua.lua")
),
new Doc(
"java", "Java",
require("ace/requirejs/text!demo/kitchen-sink/docs/java.java")
),
new Doc(
"clojure", "Clojure",
require("ace/requirejs/text!demo/kitchen-sink/docs/clojure.clj")
),
new Doc(
"groovy", "Groovy",
require("ace/requirejs/text!demo/kitchen-sink/docs/groovy.groovy")
),
new Doc(
"scala", "Scala",
require("ace/requirejs/text!demo/kitchen-sink/docs/scala.scala")
),
new Doc(
"csharp", "C#",
require("ace/requirejs/text!demo/kitchen-sink/docs/csharp.cs")
),
new Doc(
"powershell", "Powershell",
require("ace/requirejs/text!demo/kitchen-sink/docs/powershell.ps1")
),
new Doc(
"c_cpp", "C/C++",
require("ace/requirejs/text!demo/kitchen-sink/docs/cpp.cpp")
),
new Doc(
"markdown", "Markdown",
require("ace/requirejs/text!demo/kitchen-sink/docs/markdown.md")
),
new WrappedDoc(
"markdown", "Markdown",
require("ace/requirejs/text!demo/kitchen-sink/docs/markdown.md")
),
new WrappedDoc(
"textile", "Textile",
require("ace/requirejs/text!demo/kitchen-sink/docs/textile.textile")
),
new WrappedDoc(
"latex", "LaTeX",
require("ace/requirejs/text!demo/kitchen-sink/docs/latex.tex")
)
];
var docsByName = {};
docs.forEach(function(d) {
docsByName[d.name] = d;
});
var keybindings = {
// Null = use "default" keymapping
ace: null,
vim: vim,
emacs: emacs,
// This is a way to define simple keyboard remappings
custom: new HashHandler({
"gotoright": "Tab",
"indent": "]",
"outdent": "[",
"gotolinestart": "^",
"gotolineend": "$"
})
};
var container = document.getElementById("editor");
// Splitting.
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;
window.ace = env.editor;
var docEl = document.getElementById("doc");
var modeEl = document.getElementById("mode");
var wrapModeEl = document.getElementById("soft_wrap");
var themeEl = document.getElementById("theme");
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 softTabEl = document.getElementById("soft_tab");
var behavioursEl = document.getElementById("enable_behaviours");
docs.forEach(function(doc) {
var option = document.createElement("option");
option.setAttribute("value", doc.name);
option.innerHTML = doc.desc;
docEl.appendChild(option);
});
modes.forEach(function(mode) {
var option = document.createElement("option");
option.setAttribute("value", mode.name);
option.innerHTML = mode.desc;
modeEl.appendChild(option);
});
bindDropdown("doc", function(value) {
var doc = docsByName[value].doc;
var session = env.split.setSession(doc);
session.name = doc.name;
updateUIEditorOptions();
env.editor.focus();
});
function updateUIEditorOptions() {
var editor = env.editor;
var session = editor.session;
docEl.value = session.name;
modeEl.value = session.getMode().name || "text";
if (!session.getUseWrapMode()) {
wrapModeEl.value = "off";
} else {
wrapModeEl.value = session.getWrapLimitRange().min || "free";
}
selectStyleEl.checked = editor.getSelectionStyle() == "line";
themeEl.value = editor.getTheme();
highlightActiveEl.checked = editor.getHighlightActiveLine();
showHiddenEl.checked = editor.getShowInvisibles();
showGutterEl.checked = editor.renderer.getShowGutter();
showPrintMarginEl.checked = editor.renderer.getShowPrintMargin();
highlightSelectedWordE.checked = editor.getHighlightSelectedWord();
showHScrollEl.checked = editor.renderer.getHScrollBarAlwaysVisible();
softTabEl.checked = session.getUseSoftTabs();
behavioursEl.checked = editor.getBehavioursEnabled();
}
bindDropdown("mode", function(value) {
env.editor.getSession().setMode(modesByName[value].mode || modesByName.text.mode);
});
bindDropdown("theme", function(value) {
if (require.packaged) {
loadTheme(value, function() {
env.editor.setTheme(value);
});
}
else {
env.editor.setTheme(value);
}
});
bindDropdown("keybinding", function(value) {
env.editor.setKeyboardHandler(keybindings[value]);
});
bindDropdown("fontsize", function(value) {
env.split.setFontSize(value);
});
bindDropdown("soft_wrap", function(value) {
var session = env.editor.getSession();
var renderer = env.editor.renderer;
switch (value) {
case "off":
session.setUseWrapMode(false);
renderer.setPrintMarginColumn(80);
break;
case "40":
session.setUseWrapMode(true);
session.setWrapLimitRange(40, 40);
renderer.setPrintMarginColumn(40);
break;
case "80":
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
renderer.setPrintMarginColumn(80);
break;
case "free":
session.setUseWrapMode(true);
session.setWrapLimitRange(null, null);
renderer.setPrintMarginColumn(80);
break;
}
});
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("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.renderer.setHScrollBarAlwaysVisible(checked);
});
bindCheckbox("soft_tab", function(checked) {
env.editor.getSession().setUseSoftTabs(checked);
});
bindCheckbox("enable_behaviours", function(checked) {
env.editor.setBehavioursEnabled(checked);
});
var secondSession = null;
bindDropdown("split", function(value) {
var sp = env.split;
if (value == "none") {
if (sp.getSplits() == 2) {
secondSession = sp.getEditor(1).session;
}
sp.setSplits(1);
} else {
var newEditor = (sp.getSplits() == 1);
if (value == "below") {
sp.setOriantation(sp.BELOW);
} else {
sp.setOriantation(sp.BESIDE);
}
sp.setSplits(2);
if (newEditor) {
var session = secondSession || sp.getEditor(0).session;
var newSession = sp.setSession(session, 1);
newSession.name = session.name;
}
}
});
function bindCheckbox(id, callback) {
var el = document.getElementById(id);
var onCheck = function() {
callback(!!el.checked);
};
el.onclick = onCheck;
onCheck();
}
function bindDropdown(id, callback) {
var el = document.getElementById(id);
var onChange = function() {
callback(el.value);
};
el.onchange = onChange;
onChange();
}
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 + "px";
env.split.resize();
// env.editor.resize();
}
window.onresize = onResize;
env.editor.renderer.onResize(true);
event.addListener(container, "dragover", function(e) {
return event.preventDefault(e);
});
event.addListener(container, "drop", function(e) {
var file;
try {
file = e.dataTransfer.files[0];
} catch(err) {
return event.stopEvent();
}
if (window.FileReader) {
var reader = new FileReader();
reader.onload = function(e) {
env.editor.getSelection().selectAll();
var mode = modesByName.text;
for (var i = 0; i < modes.length; i++) {
if (modes[i].supportsFile(file.name)) {
mode = modes[i];
break;
}
}
env.editor.onTextInput(reader.result);
modeEl.value = mode.name;
env.editor.getSession().setMode(mode.mode);
};
reader.readAsText(file);
}
return event.preventDefault(e);
});
/**
* This demonstrates how you can define commands and bind shortcuts to them.
*/
// Fake-Save, works from the editor and the command line.
var commands = env.editor.commands;
commands.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor"
},
exec: function() {
alert("Fake Save File");
}
});
// Fake-Print with custom lookup-sender-match function.
commands.addCommand({
name: "print",
bindKey: {
win: "Ctrl-P",
mac: "Command-P",
sender: function(env, sender, hashId, keyString) {
if (sender == "editor") {
return true;
} else {
alert("Sorry, can only print from the editor");
}
}
},
exec: function() {
alert("Fake Print File");
}
});
});

View file

@ -130,4 +130,4 @@
})();
</script>
</body>
</html>
</html>

View file

@ -188,21 +188,21 @@
<!-- DEVEL-->
<script type="text/javascript">
var require = {
baseUrl: "/" + window.location.pathname.split("/").slice(0, -1).join("/"),
paths: {
demo: "..",
ace: "../../lib/ace",
cockpit: "../../node_modules/cockpit/lib/cockpit",
pilot: "../../node_modules/pilot/lib/pilot"
ace: "lib/ace",
pilot: "node_modules/pilot/lib/pilot"
}
};
</script>
<script src="demo/kitchen-sink/require.js" data-main="demo/kitchen-sink/boot" type="text/javascript" charset="utf-8"></script>
<script src="demo/kitchen-sink/require.js" data-main="demo/kitchen-sink/demo" type="text/javascript"></script>
<!--DEVEL -->
<!--PACKAGE
<script src="demo/kitchen-sink/kitchen-sink-uncompressed.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
require("demo/kitchen-sink/boot");
require("demo/kitchen-sink/demo");
</script>
<!--PACKAGE-->

View file

@ -39,8 +39,6 @@ define(function(require, exports, module) {
require("pilot/index");
require("pilot/fixoldbrowsers");
var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins([ "pilot/index" ]);
var Dom = require("pilot/dom");
var Event = require("pilot/event");
@ -62,16 +60,14 @@ define(function(require, exports, module) {
var editor = new Editor(new Renderer(el, require("ace/theme/textmate")));
editor.setSession(doc);
var env = require("pilot/environment").create();
catalog.startupPlugins({ env: env }).then(function() {
env.document = doc;
env.editor = editor;
var env = {};
env.document = doc;
env.editor = editor;
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
});
el.env = env;
});
el.env = env;
// Store env on editor such that it can be accessed later on from
// the returned object.
editor.env = env;

View file

@ -0,0 +1,87 @@
define(function(require, exports, module) {
var keyUtil = require('pilot/keys');
var useragent = require('pilot/useragent');
var CommandManager = function(commands) {
this.commands = {};
this.commmandKeyBinding = {};
if (commands)
commands.forEach(this.addCommand, this);
};
(function() {
this.addCommand = function(command) {
this.commands[command.name] = command;
if (command.bindKey) {
this._buildKeyHash(command);
}
};
var platform = useragent.isMac ? "mac" : "win";
this._buildKeyHash = function(command) {
var binding = command.bindKey;
var key = binding[platform];
var ckb = this.commmandKeyBinding;
if(!binding[platform]) {
return;
}
key.split("|").forEach(function(keyPart) {
var binding = parseKeys(keyPart, command);
var hashId = binding.hashId;
(ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
});
}
function parseKeys(keys, val, ret) {
var key;
var hashId = 0;
var parts = splitSafe(keys, "\\-", null, true);
for (var i=0, l = parts.length; i < l; i++) {
if (keyUtil.KEY_MODS[parts[i]])
hashId = hashId | keyUtil.KEY_MODS[parts[i]];
else
key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
}
return {
key: key,
hashId: hashId
}
}
function splitSafe(s, separator, limit, bLowerCase) {
return (bLowerCase && s.toLowerCase() || s)
.replace(/(?:^\s+|\n|\s+$)/g, "")
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
}
this.findKeyCommand = function findKeyCommand(env, hashId, textOrKey) {
// Convert keyCode to the string representation.
if (typeof textOrKey == "number") {
textOrKey = keyUtil.keyCodeToString(textOrKey);
}
var ckbr = this.commmandKeyBinding;
return ckbr[hashId] && ckbr[hashId][textOrKey];
}
this.exec = function(command, env, args) {
if (typeof command === 'string')
command = this.commands[command];
command.exec(env, args || {});
};
}).call(CommandManager.prototype);
exports.CommandManager = CommandManager;
});

View file

@ -41,7 +41,6 @@
define(function(require, exports, module) {
var lang = require("pilot/lang");
var canon = require("pilot/canon");
function bindKey(win, mac) {
return {
@ -51,58 +50,46 @@ function bindKey(win, mac) {
};
}
canon.addCommand({
name: "null",
exec: function(env, args, request) { }
});
canon.addCommand({
exports.commands = [{
name: "selectall",
bindKey: bindKey("Ctrl-A", "Command-A"),
exec: function(env, args, request) { env.editor.selectAll(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.selectAll(); }
}, {
name: "removeline",
bindKey: bindKey("Ctrl-D", "Command-D"),
exec: function(env, args, request) { env.editor.removeLines(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeLines(); }
}, {
name: "gotoline",
bindKey: bindKey("Ctrl-L", "Command-L"),
exec: function(env, args, request) {
exec: function(env, args) {
var line = parseInt(prompt("Enter line number:"));
if (!isNaN(line)) {
env.editor.gotoLine(line);
}
}
});
canon.addCommand({
}, {
name: "togglecomment",
bindKey: bindKey("Ctrl-7", "Command-7"),
exec: function(env, args, request) { env.editor.toggleCommentLines(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.toggleCommentLines(); }
}, {
name: "findnext",
bindKey: bindKey("Ctrl-K", "Command-G"),
exec: function(env, args, request) { env.editor.findNext(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.findNext(); }
}, {
name: "findprevious",
bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
exec: function(env, args, request) { env.editor.findPrevious(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.findPrevious(); }
}, {
name: "find",
bindKey: bindKey("Ctrl-F", "Command-F"),
exec: function(env, args, request) {
exec: function(env, args) {
var needle = prompt("Find:", env.editor.getCopyText());
env.editor.find(needle);
}
});
canon.addCommand({
}, {
name: "replace",
bindKey: bindKey("Ctrl-R", "Command-Option-F"),
exec: function(env, args, request) {
exec: function(env, args) {
var needle = prompt("Find:", env.editor.getCopyText());
if (!needle)
return;
@ -111,11 +98,10 @@ canon.addCommand({
return;
env.editor.replace(replacement, {needle: needle});
}
});
canon.addCommand({
}, {
name: "replaceall",
bindKey: bindKey("Ctrl-Shift-R", "Command-Shift-Option-F"),
exec: function(env, args, request) {
exec: function(env, args) {
var needle = prompt("Find:");
if (!needle)
return;
@ -124,274 +110,222 @@ canon.addCommand({
return;
env.editor.replaceAll(replacement, {needle: needle});
}
});
canon.addCommand({
}, {
name: "undo",
bindKey: bindKey("Ctrl-Z", "Command-Z"),
exec: function(env, args, request) { env.editor.undo(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.undo(); }
}, {
name: "redo",
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
exec: function(env, args, request) { env.editor.redo(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.redo(); }
}, {
name: "overwrite",
bindKey: bindKey("Insert", "Insert"),
exec: function(env, args, request) { env.editor.toggleOverwrite(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.toggleOverwrite(); }
}, {
name: "copylinesup",
bindKey: bindKey("Ctrl-Alt-Up", "Command-Option-Up"),
exec: function(env, args, request) { env.editor.copyLinesUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.copyLinesUp(); }
}, {
name: "movelinesup",
bindKey: bindKey("Alt-Up", "Option-Up"),
exec: function(env, args, request) { env.editor.moveLinesUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.moveLinesUp(); }
}, {
name: "selecttostart",
bindKey: bindKey("Ctrl-Shift-Home|Alt-Shift-Up", "Command-Shift-Up"),
exec: function(env, args, request) { env.editor.getSelection().selectFileStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectFileStart(); }
}, {
name: "gotostart",
bindKey: bindKey("Ctrl-Home|Ctrl-Up", "Command-Home|Command-Up"),
exec: function(env, args, request) { env.editor.navigateFileStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateFileStart(); }
}, {
name: "selectup",
bindKey: bindKey("Shift-Up", "Shift-Up"),
exec: function(env, args, request) { env.editor.getSelection().selectUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectUp(); }
}, {
name: "golineup",
bindKey: bindKey("Up", "Up|Ctrl-P"),
exec: function(env, args, request) { env.editor.navigateUp(args.times); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateUp(args.times); }
}, {
name: "copylinesdown",
bindKey: bindKey("Ctrl-Alt-Down", "Command-Option-Down"),
exec: function(env, args, request) { env.editor.copyLinesDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.copyLinesDown(); }
}, {
name: "movelinesdown",
bindKey: bindKey("Alt-Down", "Option-Down"),
exec: function(env, args, request) { env.editor.moveLinesDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.moveLinesDown(); }
}, {
name: "selecttoend",
bindKey: bindKey("Ctrl-Shift-End|Alt-Shift-Down", "Command-Shift-Down"),
exec: function(env, args, request) { env.editor.getSelection().selectFileEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectFileEnd(); }
}, {
name: "gotoend",
bindKey: bindKey("Ctrl-End|Ctrl-Down", "Command-End|Command-Down"),
exec: function(env, args, request) { env.editor.navigateFileEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateFileEnd(); }
}, {
name: "selectdown",
bindKey: bindKey("Shift-Down", "Shift-Down"),
exec: function(env, args, request) { env.editor.getSelection().selectDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectDown(); }
}, {
name: "golinedown",
bindKey: bindKey("Down", "Down|Ctrl-N"),
exec: function(env, args, request) { env.editor.navigateDown(args.times); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateDown(args.times); }
}, {
name: "selectwordleft",
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
exec: function(env, args, request) { env.editor.getSelection().selectWordLeft(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectWordLeft(); }
}, {
name: "gotowordleft",
bindKey: bindKey("Ctrl-Left", "Option-Left"),
exec: function(env, args, request) { env.editor.navigateWordLeft(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateWordLeft(); }
}, {
name: "selecttolinestart",
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
exec: function(env, args, request) { env.editor.getSelection().selectLineStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
}, {
name: "gotolinestart",
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
exec: function(env, args, request) { env.editor.navigateLineStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateLineStart(); }
}, {
name: "selectleft",
bindKey: bindKey("Shift-Left", "Shift-Left"),
exec: function(env, args, request) { env.editor.getSelection().selectLeft(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectLeft(); }
}, {
name: "gotoleft",
bindKey: bindKey("Left", "Left|Ctrl-B"),
exec: function(env, args, request) { env.editor.navigateLeft(args.times); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateLeft(args.times); }
}, {
name: "selectwordright",
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
exec: function(env, args, request) { env.editor.getSelection().selectWordRight(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectWordRight(); }
}, {
name: "gotowordright",
bindKey: bindKey("Ctrl-Right", "Option-Right"),
exec: function(env, args, request) { env.editor.navigateWordRight(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateWordRight(); }
}, {
name: "selecttolineend",
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
exec: function(env, args, request) { env.editor.getSelection().selectLineEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
}, {
name: "gotolineend",
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
exec: function(env, args, request) { env.editor.navigateLineEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateLineEnd(); }
}, {
name: "selectright",
bindKey: bindKey("Shift-Right", "Shift-Right"),
exec: function(env, args, request) { env.editor.getSelection().selectRight(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectRight(); }
}, {
name: "gotoright",
bindKey: bindKey("Right", "Right|Ctrl-F"),
exec: function(env, args, request) { env.editor.navigateRight(args.times); }
});
canon.addCommand({
exec: function(env, args) { env.editor.navigateRight(args.times); }
}, {
name: "selectpagedown",
bindKey: bindKey("Shift-PageDown", "Shift-PageDown"),
exec: function(env, args, request) { env.editor.selectPageDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.selectPageDown(); }
}, {
name: "pagedown",
bindKey: bindKey(null, "PageDown"),
exec: function(env, args, request) { env.editor.scrollPageDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.scrollPageDown(); }
}, {
name: "gotopagedown",
bindKey: bindKey("PageDown", "Option-PageDown|Ctrl-V"),
exec: function(env, args, request) { env.editor.gotoPageDown(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.gotoPageDown(); }
}, {
name: "selectpageup",
bindKey: bindKey("Shift-PageUp", "Shift-PageUp"),
exec: function(env, args, request) { env.editor.selectPageUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.selectPageUp(); }
}, {
name: "pageup",
bindKey: bindKey(null, "PageUp"),
exec: function(env, args, request) { env.editor.scrollPageUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.scrollPageUp(); }
}, {
name: "gotopageup",
bindKey: bindKey("PageUp", "Option-PageUp"),
exec: function(env, args, request) { env.editor.gotoPageUp(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.gotoPageUp(); }
}, {
name: "selectlinestart",
bindKey: bindKey("Shift-Home", "Shift-Home"),
exec: function(env, args, request) { env.editor.getSelection().selectLineStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
}, {
name: "selectlineend",
bindKey: bindKey("Shift-End", "Shift-End"),
exec: function(env, args, request) { env.editor.getSelection().selectLineEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
}, {
name: "del",
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
exec: function(env, args, request) { env.editor.remove("right"); }
});
canon.addCommand({
exec: function(env, args) { env.editor.remove("right"); }
}, {
name: "backspace",
bindKey: bindKey(
"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
),
exec: function(env, args, request) { env.editor.remove("left"); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeLeft(); }
}, {
name: "removetolinestart",
bindKey: bindKey("Alt-Backspace", "Option-Backspace"),
exec: function(env, args, request) { env.editor.removeToLineStart(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeToLineStart(); }
}, {
name: "removetolineend",
bindKey: bindKey("Alt-Delete", "Ctrl-K"),
exec: function(env, args, request) { env.editor.removeToLineEnd(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeToLineEnd(); }
}, {
name: "removewordleft",
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
exec: function(env, args, request) { env.editor.removeWordLeft(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeWordLeft(); }
}, {
name: "removewordright",
bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
exec: function(env, args, request) { env.editor.removeWordRight(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.removeWordRight(); }
}, {
name: "outdent",
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
exec: function(env, args, request) { env.editor.blockOutdent(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.blockOutdent(); }
}, {
name: "indent",
bindKey: bindKey("Tab", "Tab"),
exec: function(env, args, request) { env.editor.indent(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.indent(); }
}, {
name: "inserttext",
exec: function(env, args, request) {
exec: function(env, args) {
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
}
});
canon.addCommand({
}, {
name: "centerselection",
bindKey: bindKey(null, "Ctrl-L"),
exec: function(env, args, request) { env.editor.centerSelection(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.centerSelection(); }
}, {
name: "splitline",
bindKey: bindKey(null, "Ctrl-O"),
exec: function(env, args, request) { env.editor.splitLine(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.splitLine(); }
}, {
name: "transposeletters",
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
exec: function(env, args, request) { env.editor.transposeLetters(); }
});
canon.addCommand({
exec: function(env, args) { env.editor.transposeLetters(); }
}, {
name: "fold",
bindKey: bindKey("Alt-L", "Alt-L"),
exec: function(env) {
env.editor.session.toggleFold(false);
}
});
canon.addCommand({
}, {
name: "unfold",
bindKey: bindKey("Alt-Shift-L", "Alt-Shift-L"),
exec: function(env) {
env.editor.session.toggleFold(true);
}
});
canon.addCommand({
}, {
name: "foldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.foldAll();
}
});
canon.addCommand({
}, {
name: "unfoldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.unFoldAll();
}
});
}];
});

View file

@ -1,51 +0,0 @@
/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Ajax.org Code Editor (ACE).
*
* The Initial Developer of the Original Code is
* Ajax.org B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var settings = require("ace/settings/default-settings")
exports.startup = function startup(data, reason) {
settings.startup(data, reason)
}
exports.shutdown = function shutdown(data, reason) {
settings.shutdown(data, reason)
}
})

View file

@ -54,8 +54,10 @@ var EditSession = require("ace/edit_session").EditSession;
var Search = require("ace/search").Search;
var Range = require("ace/range").Range;
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var CommandManager = require("ace/commands/command_manager").CommandManager;
var defaultCommands = require("ace/commands/default_commands").commands;
var Editor =function(renderer, session) {
var Editor = function(renderer, session) {
var container = renderer.getContainerElement();
this.container = container;
this.renderer = renderer;
@ -75,6 +77,7 @@ var Editor =function(renderer, session) {
wrap: true
});
this.commands = new CommandManager(defaultCommands);
this.setSession(session || new EditSession(""));
};

View file

@ -41,8 +41,6 @@ define(function(require, exports, module) {
var useragent = require("pilot/useragent");
var keyUtil = require("pilot/keys");
var event = require("pilot/event");
var settings = require("pilot/settings").settings;
var canon = require("pilot/canon");
require("ace/commands/default_commands");
var KeyBinding = function(editor) {
@ -64,19 +62,21 @@ var KeyBinding = function(editor) {
};
this.$callKeyboardHandler = function (e, hashId, keyOrText, keyCode) {
var env = {editor: this.$editor},
toExecute;
var env = {editor: this.$editor};
var toExecute;
var commands = this.$editor.commands;
if (this.$keyboardHandler) {
toExecute =
this.$keyboardHandler.handleKeyboard(this.$data, hashId, keyOrText, keyCode, e);
}
// If there is nothing to execute yet, then use the default keymapping.
if (!toExecute || !toExecute.command) {
if (hashId != 0 || keyCode != 0) {
toExecute = {
command: canon.findKeyCommand(env, "editor", hashId, keyOrText)
command: commands.findKeyCommand(env, hashId, keyOrText)
}
} else {
toExecute = {
@ -89,9 +89,11 @@ var KeyBinding = function(editor) {
}
var success = false;
if (toExecute) {
success = canon.exec(toExecute.command,
env, "editor", toExecute.args);
if (toExecute && toExecute.command) {
success = commands.exec(
toExecute.command,
env, toExecute.args
);
if (success) {
event.stopEvent(e);
}

View file

@ -26,8 +26,7 @@
<script type="text/javascript">
var require = {
paths: {
ace: "../",
pilot: "../../../support/pilot/lib/pilot"
ace: "../"
},
packages : [{
name: "asyncjs",

@ -1 +0,0 @@
Subproject commit 33f02ab3af5d755c98b3c58309ac2c62fc6de736

@ -1 +0,0 @@
Subproject commit 375d9a339646d70846ad40eddaad406198dd9d40

@ -1 +0,0 @@
Subproject commit 51938ca15ac7bd16f94e534cda3779f8a0a9f130

@ -1 +0,0 @@
Subproject commit f1ac22a9bc806772ae68fd67d800fc0625518346