Merge pull request #790 from ajaxorg/ui/refactor

small bugfixes
This commit is contained in:
Fabian Jakobs 2012-06-02 11:07:55 -07:00
commit dbab677c41
37 changed files with 599 additions and 314 deletions

View file

@ -43,56 +43,61 @@ if (!fs.existsSync)
var copy = require('dryice').copy;
var ACE_HOME = __dirname;
var BUILD_DIR = "build";
function main(args) {
var target = "minimal";
if (args.length == 3) {
target = args[2];
// Check if 'target' contains some allowed value.
if (!/^(normal|bm|demo|minimal)$/.test(target))
target = "help";
}
var type = "minimal";
args = args.map(function(x) {
if (x[0] == "-" && x[1] != "-")
return "-" + x;
return x;
});
if (args[2] && (args[2][0] != "-" || args[2].indexOf("h") != -1))
type = args[2];
if (target == "help") {
console.log("--- Ace Dryice Build Tool ---");
console.log("");
console.log("Options:");
console.log(" minimal Runs minimal build of Ace");
console.log(" normal Runs embedded build of Ace");
console.log(" demo Runs demo build of Ace");
console.log(" bm Runs bookmarklet build of Ace");
process.exit(0);
}
var i = args.indexOf("--target");
if (i != -1 && args[i+1])
BUILD_DIR = args[i+1];
var aceProject = {
roots: [
ACE_HOME + '/lib',
ACE_HOME + '/demo'
],
textPluginPattern: /^ace\/requirejs\/text!/
};
if (target == "minimal") {
buildAce(aceProject, {
compress: false,
noconflict: false,
suffix: "",
name: "ace"
if (type == "minimal") {
buildAce({
compress: args.indexOf("-m") != -1,
noconflict: args.indexOf("-nc") != -1
});
} else if (type == "normal") {
ace();
} else if (type == "demo") {
demo();
} else if (type == "bm") {
bookmarklet();
} else if (type == "full") {
ace();
demo();
bookmarklet();
}
if (target == "normal") {
ace(aceProject);
}
else if (target == "demo") {
demo(aceProject);
}
else if (target == "bm") {
bookmarklet(aceProject);
}
console.log("--- Ace Dryice Build Tool ---");
console.log("");
console.log("Options:");
console.log(" normal Runs embedded build of Ace");
console.log(" demo Runs demo build of Ace");
console.log(" bm Runs bookmarklet build of Ace");
console.log(" full all of above");
console.log("flags:");
console.log(" -m minify");
console.log(" -nc namespace require");
console.log(" --target ./path path to build folder");
console.log("");
if (BUILD_DIR)
console.log(" output generated in " + type + __dirname + "/" + BUILD_DIR)
process.exit(0);
}
function bookmarklet(aceProject) {
var targetDir = "build/textarea";
function bookmarklet() {
var targetDir = BUILD_DIR + "/textarea";
copy({
source: "build_support/editor_textarea.html",
dest: targetDir + '/editor.html'
@ -102,7 +107,7 @@ function bookmarklet(aceProject) {
dest: targetDir + '/style.css'
});
buildAce(aceProject, {
buildAce({
targetDir: targetDir + "/src",
ns: "__ace_shadowed__",
exportModule: "ace/ext/textarea",
@ -115,38 +120,27 @@ function bookmarklet(aceProject) {
});
}
function ace(aceProject) {
function ace() {
console.log('# ace ---------');
// uncompressed
buildAce(aceProject, {
buildAce({
compress: false,
noconflict: false,
suffix: "",
name: "ace"
noconflict: false
});
buildAce(aceProject, {
buildAce({
compress: false,
noconflict: true,
suffix: "-noconflict",
name: "ace",
workers: []
noconflict: true
});
// compressed
buildAce(aceProject, {
buildAce({
compress: true,
noconflict: false,
suffix: "-min",
name: "ace",
workers: []
noconflict: false
});
buildAce(aceProject, {
buildAce({
compress: true,
noconflict: true,
suffix: "-min-noconflict",
name: "ace",
workers: []
noconflict: true
});
console.log('# ace License | Readme | Changelog ---------');
@ -169,7 +163,7 @@ function ace(aceProject) {
});
}
function demo(aceProject) {
function demo() {
console.log('# kitchen sink ---------');
var version, ref;
@ -182,14 +176,10 @@ function demo(aceProject) {
}
var changeComments = function(data) {
return (data
.replace("DEVEL-->", "")
.replace("<!--DEVEL", "")
.replace("PACKAGE-->", "")
.replace("<!--PACKAGE", "")
.replace("DEVEL*/", "")
.replace("/*DEVEL", "")
.replace("PACKAGE*/", "")
.replace("/*PACKAGE", "")
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%version%", version)
.replace("%commit%", ref)
);
@ -197,7 +187,7 @@ function demo(aceProject) {
copy({
source: "kitchen-sink.html",
dest: "build/kitchen-sink.html",
dest: BUILD_DIR + "/kitchen-sink.html",
filter: [changeComments, function(data) {
return data.replace(/"(demo|build)\//g, "\"");
}]
@ -205,14 +195,14 @@ function demo(aceProject) {
copy({
source: "demo/kitchen-sink/styles.css",
dest: "build/kitchen-sink/styles.css",
dest: BUILD_DIR + "/kitchen-sink/styles.css",
filter: [ changeComments ]
});
fs.readdirSync("demo/kitchen-sink/docs/").forEach(function(x) {
copy({
source: "demo/kitchen-sink/docs/" + x,
dest: "build/kitchen-sink/docs/" + x
dest: BUILD_DIR + "/kitchen-sink/docs/" + x
});
});
@ -235,22 +225,26 @@ function demo(aceProject) {
});
copy({
source: demo,
dest: "build/kitchen-sink/demo.js",
dest: BUILD_DIR + "/kitchen-sink/demo.js",
});
copyFileSync("demo/kitchen-sink/logo.png", "build/kitchen-sink/logo.png");
copyFileSync("demo/kitchen-sink/logo.png", BUILD_DIR + "/kitchen-sink/logo.png");
}
function buildAce(aceProject, options) {
function buildAce(options) {
var aceProject = {
roots: [ACE_HOME + '/lib', ACE_HOME + '/demo'],
textPluginPattern: /^ace\/requirejs\/text!/
};
var defaults = {
targetDir: __dirname + "/build/src",
targetDir: BUILD_DIR + "/src",
ns: "ace",
exportModule: "ace/ace",
requires: null,
compress: false,
noconflict: false,
suffix: "",
suffix: null,
name: "ace",
modes: fs.readdirSync("lib/ace/mode").map(function(x) {
if (x.slice(-3) == ".js" && !/_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/.test(x))
@ -262,15 +256,29 @@ function buildAce(aceProject, options) {
workers: ["javascript", "coffee", "css", "json", "xquery"],
keybindings: ["vim", "emacs"]
};
for(var key in defaults)
if (!options.hasOwnProperty(key))
options[key] = defaults[key];
if (options.suffix == null) {
options.suffix = "";
if (options.compress)
options.suffix += "-min";
if (options.noconflict)
options.suffix += "-noconflict";
}
if (!options.requires)
options.requires = [options.exportModule];
var filters = [copy.filter.moduleDefines, filterTextPlugin];
var filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
if (options.noconflict) {
filters.push(namespace(options.ns));
@ -280,20 +288,10 @@ function buildAce(aceProject, options) {
var exportFilter = exportAce(options.ns, options.exportModule);
}
// remove use strict
filters.push(function(text) {
return text.replace(/['"]use strict['"];/g, "");
})
// remove redundant comments
filters.push(function(text) {
return text.replace(/(;)\s*\/\*[\d\D]*?\*\//g, "$1");
})
if (options.compress)
filters.push(copy.filter.uglifyjs);
var suffix = options.suffix;
var targetDir = options.targetDir;
var targetDir = options.targetDir + options.suffix;
var name = options.name;
var project = copy.createCommonJsProject(aceProject);
@ -304,8 +302,8 @@ function buildAce(aceProject, options) {
});
copy({
source: [{
project: project,
require: options.requires
project: project,
require: options.requires
}],
filter: [ copy.filter.moduleDefines ],
dest: ace
@ -314,7 +312,7 @@ function buildAce(aceProject, options) {
copy({
source: ace,
filter: exportFilter ? filters.concat(exportFilter) : filters,
dest: targetDir + suffix + '/' + name + ".js"
dest: targetDir + '/' + name + ".js"
});
console.log('# ace modes ---------');
@ -324,11 +322,11 @@ function buildAce(aceProject, options) {
console.log("mode " + mode);
copy({
source: [{
project: cloneProject(project),
require: [ 'ace/mode/' + mode ]
project: cloneProject(project),
require: [ 'ace/mode/' + mode ]
}],
filter: filters,
dest: targetDir + suffix + "/mode-" + mode + ".js"
dest: targetDir + "/mode-" + mode + ".js"
});
});
@ -343,7 +341,7 @@ function buildAce(aceProject, options) {
require: ["ace/theme/" + theme]
}],
filter: filters,
dest: targetDir + suffix + "/theme-" + theme + ".js"
dest: targetDir + "/theme-" + theme + ".js"
});*/
// use this instead, to not create separate modules for js and css
var themePath = "lib/ace/theme/" + theme
@ -356,43 +354,7 @@ function buildAce(aceProject, options) {
}
filters.forEach(function(f) {js = f(js); });
fs.writeFileSync(targetDir + suffix + "/theme-" + theme + ".js", js);
});
console.log('# ace worker ---------');
options.workers.forEach(function(mode) {
console.log("worker for " + mode + " mode");
var worker = copy.createDataObject();
var workerProject = copy.createCommonJsProject({
roots: [
ACE_HOME + '/lib'
],
textPluginPattern: /^ace\/requirejs\/text!/
});
copy({
source: [
{
project: workerProject,
require: [
'ace/lib/fixoldbrowsers',
'ace/lib/event_emitter',
'ace/lib/oop',
'ace/mode/' + mode + '_worker'
]
}
],
filter: [ copy.filter.moduleDefines, filterTextPlugin ],
dest: worker
});
copy({
source: [
ACE_HOME + "/lib/ace/worker/worker.js",
worker
],
filter: [ /* copy.filter.uglifyjs */],
dest: targetDir + "/worker-" + mode + ".js"
});
fs.writeFileSync(targetDir + "/theme-" + theme + ".js", js);
});
console.log('# ace key bindings ---------');
@ -406,9 +368,49 @@ function buildAce(aceProject, options) {
require: [ 'ace/keyboard/' + keybinding ]
}],
filter: filters,
dest: targetDir + suffix + "/keybinding-" + keybinding + ".js"
dest: targetDir + "/keybinding-" + keybinding + ".js"
});
});
console.log('# ace worker ---------');
filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
options.workers.forEach(function(mode) {
console.log("worker for " + mode + " mode");
var worker = copy.createDataObject();
var workerProject = copy.createCommonJsProject({
roots: [ ACE_HOME + '/lib' ],
textPluginPattern: /^ace\/requirejs\/text!/
});
copy({
source: [{
project: workerProject,
require: [
'ace/lib/fixoldbrowsers',
'ace/lib/event_emitter',
'ace/lib/oop',
'ace/mode/' + mode + '_worker'
]
}],
filter: filters,
dest: worker
});
copy({
source: [
ACE_HOME + "/lib/ace/worker/worker.js",
worker
],
filter: options.compress ? [copy.filter.uglifyjs] : [],
dest: targetDir + "/worker-" + mode + ".js"
});
});
}
// TODO: replace with project.clone once it is fixed in dryice
@ -459,6 +461,14 @@ function filterTextPlugin(text) {
return text.replace(/(['"])ace\/requirejs\/text\!/g, "$1text!");
}
function removeUseStrict(text) {
return text.replace(/['"]use strict['"];/g, "");
}
function removeLicenceCmments(text) {
return text.replace(/(;)\s*\/\*[\d\D]*?\*\//g, "$1");
}
function namespace(ns) {
return function(text) {
text = text

View file

@ -10,7 +10,7 @@ Features
* Automatic indent and outdent
* An optional command line
* Handles huge documents (100,000 lines and more are no problem)
* Fully customizable key bindings including VI and Emacs modes
* Fully customizable key bindings including VIM and Emacs modes
* Themes (TextMate themes can be imported)
* Search and replace with regular expressions
* Highlight matching parentheses
@ -18,20 +18,16 @@ Features
* Displays hidden characters
* Drag and drop text using the mouse
* Line wrapping
* Unstructured / user code folding
* Live syntax checker (currently JavaScript/CoffeeScript)
* Code folding
* Multiple selections
* Live syntax checker (currently JavaScript/CoffeeScript/Css/XQuery)
Take Ace for a spin!
--------------------
Check out the Ace live [demo](http://ajaxorg.github.com/ace/) or get a [Cloud9 IDE account](http://run.cloud9ide.com) to experience Ace while editing one of your own GitHub projects.
Check out the Ace live [demo](http://ajaxorg.github.com/ace-builds/kitchen-sink.html) or get a [Cloud9 IDE account](http://c9.io) to experience Ace while editing one of your own GitHub projects.
If you want, you can use Ace as a textarea replacement thanks to the [Ace Bookmarklet](http://ajaxorg.github.com/ace/build/textarea/editor.html).
History
-------
Previously known as “Bespin” and “Skywriter” its now known as Ace (Ajax.org Cloud9 Editor)! Bespin and Ace started as two independent projects, both aiming to build a no-compromise code editor component for the web. Bespin started as part of Mozilla Labs and was based on the canvas tag, while Ace is the Editor component of the Cloud9 IDE and is using the DOM for rendering. After the release of Ace at JSConf.eu 2010 in Berlin the Skywriter team decided to merge Ace with a simplified version of Skywriter's plugin system and some of Skywriter's extensibility points. All these changes have been merged back to Ace. Both Ajax.org and Mozilla are actively developing and maintaining Ace.
If you want, you can use Ace as a textarea replacement thanks to the [Ace Bookmarklet](http://ajaxorg.github.com/ace-builds/textarea/editor.html).
Getting the code
----------------
@ -40,14 +36,13 @@ Ace is a community project. We actively encourage and support contributions. The
```bash
git clone git://github.com/ajaxorg/ace.git
cd ace
git submodule update --init --recursive
```
Embedding Ace
-------------
Ace can be easily embedded into any existing web page. The Ace git repository ships with a pre-packaged version of Ace inside of the `build` directory. The same packaged files are also available as a separate [download](https://github.com/ajaxorg/ace/downloads). Simply copy the contents of the `src` subdirectory somewhere into your project and take a look at the included demos of how to use Ace.
Ace can be easily embedded into any existing web page. You can either use one of pre-packaged versions of [ace](https://github.com/ajaxorg/ace-builds/) (just copy one of `src*` subdirectories somewhere into your project), or use requireJS to load contents of [lib/ace](https://github.com/ajaxorg/ace/tree/master/lib/ace) as `ace`
The easiest version is simply:
@ -55,9 +50,7 @@ The easiest version is simply:
<div id="editor">some text</div>
<script src="src/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
window.onload = function() {
var editor = ace.edit("editor");
};
</script>
```
@ -96,10 +89,14 @@ Then the mode can be used like this:
editor.getSession().setMode(new JavaScriptMode());
```
and take a look at the one of [included](https://github.com/ajaxorg/ace-builds/blob/master/editor.html) [demos](https://github.com/ajaxorg/ace/blob/master/demo/kitchen-sink/demo.js) of how to use Ace.
Documentation
-------------
You find a lot more sample code in the [demo app](https://github.com/ajaxorg/ace/blob/master/demo/demo.js).
You can find api documentation at [http://ajaxorg.github.com/ace/api/index.html](http://ajaxorg.github.com/ace/api/index.html).
And a lot more sample code in the [demo app](https://github.com/ajaxorg/ace/blob/master/demo/kitchen-sink/demo.js).
There is also some documentation on the [wiki page](https://github.com/ajaxorg/ace/wiki).
@ -126,42 +123,17 @@ The editor can then be opened at http://localhost:8888/index.html.
Package Ace
-----------
To package Ace we use the dryice build tool developed by the Mozilla Skywriter team. Before you can build you need to make sure that the submodules are up to date.
To package Ace we use the dryice build tool developed by the Mozilla Skywriter team. Make sure you at latest version of dryice
```bash
git submodule update --init --recursive
```
Make sure you at least version 0.3.0 of dryice
```bash
npm install dryice
```
Afterwards Ace can be built by calling
```bash
./Makefile.dryice.js normal
```
The packaged Ace will be put in the 'build' folder.
To build the bookmarklet version execute
```bash
./Makefile.dryice.js bm
npm install
node ./Makefile.dryice.js ;; -m to minify, -nc to use namespaced requre, -target ./path/to/build/dir
```
Running the Unit Tests
----------------------
The Ace unit tests run on node.js. Before the first run a couple of node modules have to be installed. The easiest way to do this is by using the node package manager (npm). In the Ace base directory simply call
```bash
npm link .
```
To run the tests call:
The Ace unit tests can run on node.js. Assuming you have already done `npm install`, just call:
```bash
node lib/ace/test/all.js

View file

@ -66,7 +66,7 @@ if (location.protocol == "file:")
EditSession.prototype.$useWorker = false;
/************** modes ***********************/
var modesByName;
var modes = [];
function getModeFromPath(path) {
var mode = modesByName.text;
for (var i = 0; i < modes.length; i++) {
@ -82,57 +82,60 @@ var Mode = function(name, desc, extensions) {
this.name = name;
this.desc = desc;
this.mode = "ace/mode/" + name;
this.extRe = new RegExp("^.*\\.(" + extensions.join("|") + ")$", "g");
this.extRe = new RegExp("^.*\\.(" + extensions + ")$", "g");
};
Mode.prototype.supportsFile = function(filename) {
return filename.match(this.extRe);
};
var modes = [
new Mode("c_cpp", "C/C++", ["c", "cpp", "cxx", "h", "hpp"]),
new Mode("clojure", "Clojure", ["clj"]),
new Mode("coffee", "CoffeeScript", ["coffee"]),
new Mode("coldfusion", "ColdFusion", ["cfm"]),
new Mode("csharp", "C#", ["cs"]),
new Mode("css", "CSS", ["css"]),
new Mode("golang", "Go", ["go"]),
new Mode("groovy", "Groovy", ["groovy"]),
new Mode("haxe", "haXe", ["hx"]),
new Mode("html", "HTML", ["html", "htm"]),
new Mode("java", "Java", ["java"]),
new Mode("diff", "Diff", ["diff", "patch"]),
new Mode("javascript", "JavaScript", ["js"]),
new Mode("json", "JSON", ["json"]),
new Mode("latex", "LaTeX", ["tex"]),
new Mode("less", "LESS", ["less"]),
new Mode("lua", "Lua", ["lua"]),
new Mode("liquid", "Liquid", ["liquid"]),
new Mode("markdown", "Markdown", ["md", "markdown"]),
new Mode("ocaml", "OCaml", ["ml", "mli"]),
new Mode("scad", "OpenSCAD", ["scad"]),
new Mode("perl", "Perl", ["pl", "pm"]),
new Mode("pgsql", "pgSQL", ["pgsql", "sql"]),
new Mode("php", "PHP", ["php"]),
new Mode("powershell", "Powershell", ["ps1"]),
new Mode("python", "Python", ["py"]),
new Mode("scala", "Scala", ["scala"]),
new Mode("scss", "SCSS", ["scss"]),
new Mode("ruby", "Ruby", ["rb"]),
new Mode("sql", "SQL", ["sql"]),
new Mode("svg", "SVG", ["svg"]),
new Mode("text", "Text", ["txt"]),
new Mode("textile", "Textile", ["textile"]),
new Mode("xml", "XML", ["xml"]),
new Mode("sh", "SH", ["sh"]),
new Mode("xquery", "XQuery", ["xq"]),
new Mode("yaml", "YAML", ["yaml"])
];
var modesByName = {
coffee: ["CoffeeScript" , "coffee|^Cakefile"],
coldfusion: ["ColdFusion" , "cfm"],
csharp: ["C#" , "cs"],
css: ["CSS" , "css"],
diff: ["Diff" , "diff|patch"],
golang: ["Go" , "go"],
groovy: ["Groovy" , "groovy"],
haxe: ["haXe" , "hx"],
html: ["HTML" , "htm|html|xhtml"],
c_cpp: ["C/C++" , "c|cc|cpp|cxx|h|hh|hpp"],
clojure: ["Clojure" , "clj"],
java: ["Java" , "java"],
javascript: ["JavaScript" , "js"],
json: ["JSON" , "json"],
latex: ["LaTeX" , "latex|tex|ltx|bib"],
less: ["LESS" , "less"],
liquid: ["Liquid" , "liquid"],
lua: ["Lua" , "lua"],
markdown: ["Markdown" , "md|markdown"],
ocaml: ["OCaml" , "ml|mli"],
perl: ["Perl" , "pl|pm"],
pgsql: ["pgSQL" , "pgsql"],
php: ["PHP" , "php|phtml"],
powershell: ["Powershell" , "ps1"],
python: ["Python" , "py"],
ruby: ["Ruby" , "ru|gemspec|rake|rb"],
scad: ["OpenSCAD" , "scad"],
scala: ["Scala" , "scala"],
scss: ["SCSS" , "scss|sass"],
sh: ["SH" , "sh|bash|bat"],
sql: ["SQL" , "sql"],
svg: ["SVG" , "svg"],
text: ["Text" , "txt"],
textile: ["Textile" , "textile"],
xml: ["XML" , "xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
xquery: ["XQuery" , "xq"],
yaml: ["YAML" , "yaml"]
};
for (var name in modesByName) {
var mode = modesByName[name];
mode = new Mode(name, mode[0], mode[1])
modesByName[name] = mode;
modes.push(mode);
}
modesByName = {};
modes.forEach(function(m) {
modesByName[m.name] = m;
});
/*********** demo documents ***************************/
var fileCache = {};
@ -259,18 +262,6 @@ window.env = env;
window.editor = window.ace = env.editor;
env.editor.setAnimatedScroll(true);
var consoleHight = 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 - consoleHight + "px";
env.split.resize();
consoleEl.style.width = width + "px";
cmdLine.resize()
}
var consoleEl = dom.createElement("div");
container.parentNode.appendChild(consoleEl);
consoleEl.style.position="fixed"
@ -331,9 +322,6 @@ cmdLine.commands.bindKeys({
cmdLine.commands.removeCommands(["find", "goToLine", "findAll", "replace", "replaceAll"])
window.onresize = onResize;
onResize();
/**
* This demonstrates how you can define commands and bind shortcuts to them.
*/
@ -368,6 +356,22 @@ var keybindings = {
/*********** manage layout ***************************/
var consoleHight = 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 - consoleHight + "px";
env.split.resize();
consoleEl.style.width = width + "px";
cmdLine.resize()
}
window.onresize = onResize;
onResize();
/*********** options pane ***************************/
var docEl = document.getElementById("doc");
var modeEl = document.getElementById("mode");
@ -654,24 +658,22 @@ event.addListener(container, "drop", function(e) {
var file;
try {
file = e.dataTransfer.files[0];
if (window.FileReader) {
var reader = new FileReader();
reader.onload = function() {
var mode = getModeFromPath(file.name);
env.editor.session.doc.setValue(reader.result);
modeEl.value = mode.name;
env.editor.session.setMode(mode.mode);
env.editor.session.modeName = mode.name;
};
reader.readAsText(file);
}
return event.preventDefault(e);
} catch(err) {
return event.stopEvent();
return event.stopEvent(e);
}
if (window.FileReader) {
var reader = new FileReader();
reader.onload = function() {
var mode = getModeFromPath(file.name);
env.editor.session.doc.setValue(reader.result);
modeEl.value = mode.name;
env.editor.session.setMode(mode.mode);
env.editor.session.modeName = mode.name;
};
reader.readAsText(file);
}
return event.preventDefault(e);
});
// add multiple cursor support to editor

View file

@ -110,7 +110,7 @@
<h2>Take Ace for a spin!</h2>
<div class="divider"></div>
<p>Check out the <a href="build/kitchen-sink.html">Ace live demo</a> or get a <a href="http://c9.io">Cloud9 IDE account</a> to experience Ace while editing one of your own GitHub projects.</p>
<p>Check out the <a href="http://ajaxorg.github.com/ace-builds/kitchen-sink.html">Ace live demo</a> or get a <a href="http://c9.io">Cloud9 IDE account</a> to experience Ace while editing one of your own GitHub projects.</p>
<h2>History</h2>
<div class="divider"></div>

View file

@ -13,9 +13,19 @@
commit %commit%
-->
<!--DEVEL-->
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<!--DEVEL-->
<!--PACKAGE
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
PACKAGE-->
</head>
<body>
<img id="logo" src="demo/kitchen-sink/logo.png">
<a href="http://ajaxorg.github.com/ace/" >
<img id="logo" src="demo/kitchen-sink/logo.png">
</a>
<table id="controls">
<tr>
<td>
@ -216,8 +226,7 @@
</div>
<div id="editor"></div>
<!-- DEVEL-->
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<!--DEVEL-->
<script type="text/javascript">
var require = {
baseUrl: window.location.protocol + "//" + window.location.host + window.location.pathname.split("/").slice(0, -1).join("/"),
@ -228,10 +237,9 @@
</script>
<script src="demo/kitchen-sink/require.js" data-main="demo/kitchen-sink/demo" type="text/javascript"></script>
<!--DEVEL -->
<!--DEVEL-->
<!--PACKAGE
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
<script src="src/keybinding-vim.js"></script>
<script src="src/keybinding-emacs.js"></script>

View file

@ -53,34 +53,34 @@ function forceTokenize(session){
}
function testStates(session, states) {
for (var i = 0, l = session.getLength(); i < l; i++)
assert.equal(session.bgTokenizer.states[i], states[i])
assert.ok(l == states.length)
for (var i = 0, l = session.getLength(); i < l; i++)
assert.equal(session.bgTokenizer.states[i], states[i])
assert.ok(l == states.length)
}
module.exports = {
"test background tokenizer update on session change" : function() {
var doc = new EditSession([
"/*",
"*/",
"var juhu"
]);
doc.setMode("ace/mode/javascript")
forceTokenize(doc)
"/*",
"*/",
"var juhu"
]);
doc.setMode("./mode/javascript")
forceTokenize(doc)
testStates(doc, ["comment", "start", "start"])
doc.remove(new Range(0,2,1,2))
testStates(doc, [null, "start"])
forceTokenize(doc)
doc.remove(new Range(0,2,1,2))
testStates(doc, [null, "start"])
forceTokenize(doc)
testStates(doc, ["comment", "comment"])
doc.insert({row:0, column:2}, "\n*/")
testStates(doc, [undefined, undefined, "comment"])
forceTokenize(doc)
doc.insert({row:0, column:2}, "\n*/")
testStates(doc, [undefined, undefined, "comment"])
forceTokenize(doc)
testStates(doc, ["comment", "start", "start"])
}
};

View file

@ -708,15 +708,18 @@ var EditSession = function(text, mode) {
var line = this.getLine(row);
var inToken = false;
if (column > 0) {
if (column > 0)
inToken = !!line.charAt(column - 1).match(this.tokenRe);
}
if (!inToken) {
if (!inToken)
inToken = !!line.charAt(column).match(this.tokenRe);
}
var re = inToken ? this.tokenRe : this.nonTokenRe;
if (inToken)
var re = this.tokenRe;
else if (/^\s+$/.test(line.slice(column-1, column+1)))
var re = /\s/;
else
var re = this.nonTokenRe;
var start = column;
if (start > 0) {

View file

@ -397,6 +397,9 @@ var Editor = function(renderer, session) {
* Emitted once the editor comes into focus.
**/
this.onFocus = function() {
if (this.$isFocused)
return;
this.$isFocused = true;
this.renderer.showCursor();
this.renderer.visualizeFocus();
this._emit("focus");
@ -408,6 +411,9 @@ var Editor = function(renderer, session) {
* Emitted once the editor has been blurred.
**/
this.onBlur = function() {
if (!this.$isFocused)
return;
this.$isFocused = false;
this.renderer.hideCursor();
this.renderer.visualizeBlur();
this._emit("blur");

View file

@ -5,10 +5,13 @@ define(function(require, exports, module) {
var Tokenizer = require("../tokenizer").Tokenizer;
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);

View file

@ -73,6 +73,14 @@ var GroovyHighlightRules = function() {
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string",
regex : '"""',
next : "qqstring"
}, {
token : "string",
regex : "'''",
next : "qstring"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
@ -130,6 +138,38 @@ var GroovyHighlightRules = function() {
merge : true,
regex : ".+"
}
],
"qqstring" : [
{
token : "constant.language.escape",
regex : /\\(?:u[0-9A-Fa-f]{4}|.|$)/
}, {
token : "constant.language.escape",
regex : /\$[\w\d]+/
}, {
token : "constant.language.escape",
regex : /\$\{[^"\}]+\}?/
}, {
token : "string",
regex : '"{3,5}',
next : "start"
}, {
token : "string",
regex : '.+?'
}
],
"qstring" : [
{
token : "constant.language.escape",
regex : /\\(?:u[0-9A-Fa-f]{4}|.|$)/
}, {
token : "string",
regex : "'{3,5}",
next : "start"
}, {
token : "string",
regex : ".+?"
}
]
};

View file

@ -75,11 +75,16 @@ var ScalaHighlightRules = function() {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
token : "string",
regex : '"""',
next : "tstring"
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
token : "string",
regex : '"(?=.)', // " strings can't span multiple lines
next : "string"
}, {
token : "symbol.constant", // single line
regex : "'[\\w\\d_]+"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
@ -131,6 +136,36 @@ var ScalaHighlightRules = function() {
merge : true,
regex : ".+"
}
],
"string" : [
{
token : "escape",
regex : '\\\\"',
}, {
token : "string",
merge : true,
regex : '"',
next : "start"
}, {
token : "string.invalid",
regex : '[^"\\\\]*$',
next : "start"
}, {
token : "string",
regex : '[^"\\\\]+',
merge : true
}
],
"tstring" : [
{
token : "string", // closing comment
regex : '"{3,5}',
next : "start"
}, {
token : "string", // comment spanning whole line
merge : true,
regex : ".+?"
}
]
};

View file

@ -57,7 +57,7 @@ function DefaultHandlers(mouseHandler) {
editor.setDefaultHandler("mousewheel", this.onScroll.bind(mouseHandler));
var exports = ["select", "startSelect", "drag", "dragEnd", "dragWait",
"dragWaitEnd", "startDrag"];
"dragWaitEnd", "startDrag", "focusWait"];
exports.forEach(function(x) {
mouseHandler[x] = this[x];
@ -98,8 +98,9 @@ function DefaultHandlers(mouseHandler) {
if (inSelection && !editor.isFocused()) {
editor.focus();
if (this.$focusWaitTimout && !this.$clickSelection) {
// todo start select after focusWaitTimout passes
return;
this.setState("focusWait");
this.captureMouse(ev);
return ev.preventDefault();
}
}
@ -212,6 +213,14 @@ function DefaultHandlers(mouseHandler) {
editor.keyBinding.addKeyboardHandler(this.$dragKeybinding);
};
this.focusWait = function() {
var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
var time = (new Date()).getTime();
if (distance > DRAG_OFFSET ||time - this.mousedownEvent.time > this.$focusWaitTimout)
this.startSelect();
};
this.dragWait = function() {
var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
var time = (new Date()).getTime();
@ -219,7 +228,7 @@ function DefaultHandlers(mouseHandler) {
if (distance > DRAG_OFFSET) {
this.startSelect();
} else if ((time - this.mousedownEvent.time) > editor.getDragDelay()) {
} else if (time - this.mousedownEvent.time > editor.getDragDelay()) {
this.startDrag()
}
};

View file

@ -0,0 +1,105 @@
/* 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):
*
* 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) {
"use strict";
var event = require("../lib/event");
var DragdropHandler = function(mouseHandler) {
var editor = mouseHandler.editor;
var dragSelectionMarker, x, y;
var timerId, range, isBackwards;
var dragCursor, counter = 0;
var mouseTarget = editor.container;
event.addListener(mouseTarget, "dragenter", function(e) {console.log(e.type, counter,e.target);
counter++;
if (!dragSelectionMarker) {
range = editor.getSelectionRange();
isBackwards = editor.selection.isBackwards();
var style = editor.getSelectionStyle();
dragSelectionMarker = editor.session.addMarker(range, "ace_selection", style);
editor.clearSelection();
clearInterval(timerId);
timerId = setInterval(onDragInterval, 20);
}
return event.preventDefault(e);
});
event.addListener(mouseTarget, "dragover", function(e) {
x = e.clientX;
y = e.clientY;
return event.preventDefault(e);
});
var onDragInterval = function() {
dragCursor = editor.renderer.screenToTextCoordinates(x, y);
editor.moveCursorToPosition(dragCursor);
editor.renderer.scrollCursorIntoView();
};
event.addListener(mouseTarget, "dragleave", function(e) {console.log(e.type, counter,e.target);
counter--;
if (counter > 0)
return;
console.log(e.type, counter,e.target);
clearInterval(timerId);
editor.session.removeMarker(dragSelectionMarker);
dragSelectionMarker = null;
editor.selection.setSelectionRange(range, isBackwards);
return event.preventDefault(e);
});
event.addListener(mouseTarget, "drop", function(e) {
console.log(e.type, counter,e.target);
counter = 0;
clearInterval(timerId);
editor.session.removeMarker(dragSelectionMarker);
dragSelectionMarker = null;
range.end = editor.session.insert(dragCursor, e.dataTransfer.getData('Text'));
range.start = dragCursor;
editor.focus();
editor.selection.setSelectionRange(range);
return event.preventDefault(e);
});
};
exports.DragdropHandler = DragdropHandler;
});

View file

@ -44,12 +44,14 @@ var event = require("../lib/event");
var DefaultHandlers = require("./default_handlers").DefaultHandlers;
var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
var MouseEvent = require("./mouse_event").MouseEvent;
var DragdropHandler = require("./dragdrop").DragdropHandler;
var MouseHandler = function(editor) {
this.editor = editor;
new DefaultHandlers(this);
new DefaultGutterHandler(this);
new DragdropHandler(this);
event.addListener(editor.container, "mousedown", function(e) {
editor.focus();

View file

@ -196,10 +196,9 @@ var RangeList = function() {
var lineDif = endRow - startRow;
var colDiff = -start.column + end.column;
var ranges = this.ranges;
for (var i=0, n = ranges.length; i < n; i++) {
for (var i = 0, n = ranges.length; i < n; i++) {
var r = ranges[i];
if (r.end.row < startRow)
continue;

View file

@ -722,8 +722,17 @@ var Selection = function(session) {
if (fold)
return this.moveCursorTo(fold.end.row, fold.end.column);
if (column == line.length)
return this.moveCursorRight();
if (column == line.length) {
var l = this.doc.getLength();
do {
row++;
rightOfCursor = this.doc.getLine(row)
} while (row < l && /^\s*$/.test(rightOfCursor))
if (!/^\s+/.test(rightOfCursor))
rightOfCursor = ""
column = 0;
}
var index = this.$shortWordEndIndex(rightOfCursor);
@ -738,11 +747,19 @@ var Selection = function(session) {
if (fold = this.session.getFoldAt(row, column, -1))
return this.moveCursorTo(fold.start.row, fold.start.column);
if (column == 0)
return this.moveCursorLeft();
var line = this.session.getLine(row).substring(0, column);
if (column == 0) {
do {
row--;
line = this.doc.getLine(row);
} while (row > 0 && /^\s*$/.test(line))
column = line.length;
if (!/\s+$/.test(line))
line = ""
}
var str = this.session.getLine(row).substring(0, column);
var leftOfCursor = lang.stringReverse(str);
var leftOfCursor = lang.stringReverse(line);
var index = this.$shortWordEndIndex(leftOfCursor);
return this.moveCursorTo(row, column - index);

View file

@ -57,6 +57,10 @@
background: #FFFBD1;
}
.ace-clouds .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-clouds .ace_marker-layer .ace_selected_word {
border: 1px solid #BDD5FC;
}

View file

@ -57,6 +57,10 @@
background: rgba(215, 215, 215, 0.031);
}
.ace-clouds-midnight .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-clouds-midnight .ace_marker-layer .ace_selected_word {
border: 1px solid #000000;
}

View file

@ -57,6 +57,10 @@
background: rgba(0, 0, 0, 0.35);
}
.ace-cobalt .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-cobalt .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(179, 101, 57, 0.75);
}

View file

@ -57,6 +57,10 @@
background: rgba(36, 99, 180, 0.12);
}
.ace-dawn .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-dawn .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(39, 95, 255, 0.30);
}

View file

@ -57,6 +57,10 @@
background: #353637;
}
.ace-idle-fingers .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-idle-fingers .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(90, 100, 126, 0.88);
}

View file

@ -57,6 +57,10 @@
background: #38403D;
}
.ace-kr-theme .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-kr-theme .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(170, 0, 255, 0.45);
}

View file

@ -57,6 +57,10 @@
background: #333435;
}
.ace-merbivore .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-merbivore .ace_marker-layer .ace_selected_word {
border: 1px solid #454545;
}

View file

@ -57,6 +57,10 @@
background: #333435;
}
.ace-merbivore-soft .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-merbivore-soft .ace_marker-layer .ace_selected_word {
border: 1px solid #494949;
}

View file

@ -57,6 +57,10 @@
background: rgba(12, 13, 12, 0.25);
}
.ace-mono-industrial .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-mono-industrial .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(145, 153, 148, 0.40);
}

View file

@ -53,11 +53,11 @@
border: 1px solid #49483E;
}
.ace-monokai .ace_marker-layer .ace_active_line{
.ace-monokai .ace_marker-layer .ace_active_line {
background: #49483E;
}
.ace-monokai .ace_gutter_active_line{
background: #191916;
.ace-monokai .ace_gutter_active_line {
background-color: #191916;
}
.ace-monokai .ace_marker-layer .ace_selected_word {

View file

@ -57,6 +57,10 @@
background: rgba(255, 255, 255, 0.031);
}
.ace-pastel-on-dark .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-pastel-on-dark .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(221, 240, 255, 0.20);
}

View file

@ -56,8 +56,9 @@
.ace-solarized-dark .ace_marker-layer .ace_active_line {
background: #073642;
}
.ace-solarized-dark .ace_gutter_active_line{
background: #0d3440;
.ace-solarized-dark .ace_gutter_active_line {
background-color: #0d3440;
}
.ace-solarized-dark .ace_marker-layer .ace_selected_word {

View file

@ -57,6 +57,10 @@
background: #EEE8D5;
}
.ace-solarized-light .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-solarized-light .ace_marker-layer .ace_selected_word {
border: 1px solid #073642;
}

View file

@ -57,6 +57,10 @@
background: #EFEFEF;
}
.ace-tomorrow .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-tomorrow .ace_marker-layer .ace_selected_word {
border: 1px solid #D6D6D6;
}

View file

@ -57,6 +57,10 @@
background: #282A2E;
}
.ace-tomorrow-night .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-tomorrow-night .ace_marker-layer .ace_selected_word {
border: 1px solid #373B41;
}

View file

@ -53,11 +53,12 @@
border: 1px solid #404F7D;
}
.ace-tomorrow-night-blue .ace_marker-layer .ace_active_line{
.ace-tomorrow-night-blue .ace_marker-layer .ace_active_line {
background: #00346E;
}
.ace-tomorrow-night-blue .ace_gutter_active_line{
background: #022040;
.ace-tomorrow-night-blue .ace_gutter_active_line {
background-color: #022040;
}
.ace-tomorrow-night-blue .ace_marker-layer .ace_selected_word {

View file

@ -57,6 +57,10 @@
background: #2A2A2A;
}
.ace-tomorrow-night-bright .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-tomorrow-night-bright .ace_marker-layer .ace_selected_word {
border: 1px solid #424242;
}

View file

@ -57,6 +57,10 @@
background: #393939;
}
.ace-tomorrow-night-eighties .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-tomorrow-night-eighties .ace_marker-layer .ace_selected_word {
border: 1px solid #515151;
}

View file

@ -57,6 +57,10 @@
background: rgba(255, 255, 255, 0.031);
}
.ace-twilight .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-twilight .ace_marker-layer .ace_selected_word {
border: 1px solid rgba(221, 240, 255, 0.20);
}

View file

@ -57,6 +57,10 @@
background: #333333;
}
.ace-vibrant-ink .ace_gutter_active_line {
background-color : #dcdcdc;
}
.ace-vibrant-ink .ace_marker-layer .ace_selected_word {
border: 1px solid #6699CC;
}

View file

@ -57,6 +57,10 @@
background: %active_line%;
}
.%cssClass% .ace_gutter_active_line {
background-color : #dcdcdc;
}
.%cssClass% .ace_marker-layer .ace_selected_word {
%selected_word_highlight%
}