This commit is contained in:
William Candillon 2012-06-04 09:50:22 +02:00
commit cc8dd79c3f
74 changed files with 1947 additions and 1040 deletions

View file

@ -1,6 +1,6 @@
.PHONY : doc build clean dist
build:
pre_build:
git rev-parse HEAD > .git-ref
mkdir -p build/src
mkdir -p build/demo/kitchen-sink
@ -9,7 +9,8 @@ build:
cp -r demo/kitchen-sink/styles.css build/demo/kitchen-sink/styles.css
cp demo/kitchen-sink/logo.png build/demo/kitchen-sink/logo.png
cp -r doc/site/images build/textarea
build: pre_build
./Makefile.dryice.js normal
./Makefile.dryice.js demo
./Makefile.dryice.js bm

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,56 +341,20 @@ 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
var js = fs.readFileSync(themePath + ".js", "utf8")
js = js.replace("define(", "define('ace/theme/" + theme + "',")
var js = fs.readFileSync(themePath + ".js", "utf8");
js = js.replace("define(", "define('ace/theme/" + theme + "', ['require', 'exports', 'module', 'ace/lib/dom'], ");
if (fs.existsSync(themePath + ".css", "utf8")) {
var css = fs.readFileSync(themePath + ".css", "utf8")
js = js.replace(/require\(.ace\/requirejs\/text!.*?\)/, quoteString(css))
}
filters.forEach(function(f) {js = f(js); })
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” it’s 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,56 +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("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 = {};
@ -165,6 +169,7 @@ var docs = {
"docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true},
"docs/coffeescript.coffee": "Coffeescript",
"docs/json.json": "JSON",
"docs/diff.diff": "Diff",
"docs/css.css": "CSS",
"docs/scss.scss": "SCSS",
"docs/less.less": "LESS",
@ -257,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"
@ -329,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.
*/
@ -366,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");
@ -652,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

@ -0,0 +1,69 @@
diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js
index 23fc3fc..ed3b273 100644
--- a/lib/ace/edit_session.js
+++ b/lib/ace/edit_session.js
@@ -51,6 +51,7 @@ var TextMode = require("./mode/text").Mode;
var Range = require("./range").Range;
var Document = require("./document").Document;
var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
+var SearchHighlight = require("./search_highlight").SearchHighlight;
/**
* class EditSession
@@ -307,6 +308,13 @@ var EditSession = function(text, mode) {
return token;
};
+ this.highlight = function(re) {
+ if (!this.$searchHighlight) {
+ var highlight = new SearchHighlight(null, "ace_selected_word", "text");
+ this.$searchHighlight = this.addDynamicMarker(highlight);
+ }
+ this.$searchHighlight.setRegexp(re);
+ }
/**
* EditSession.setUndoManager(undoManager)
* - undoManager (UndoManager): The new undo manager
@@ -556,7 +564,8 @@ var EditSession = function(text, mode) {
type : type || "line",
renderer: typeof type == "function" ? type : null,
clazz : clazz,
- inFront: !!inFront
+ inFront: !!inFront,
+ id: id
}
if (inFront) {
diff --git a/lib/ace/editor.js b/lib/ace/editor.js
index 834e603..b27ec73 100644
--- a/lib/ace/editor.js
+++ b/lib/ace/editor.js
@@ -494,7 +494,7 @@ var Editor = function(renderer, session) {
* Emitted when a selection has changed.
**/
this.onSelectionChange = function(e) {
- var session = this.getSession();
+ var session = this.session;
if (session.$selectionMarker) {
session.removeMarker(session.$selectionMarker);
@@ -509,12 +509,40 @@ var Editor = function(renderer, session) {
this.$updateHighlightActiveLine();
}
- var self = this;
- if (this.$highlightSelectedWord && !this.$wordHighlightTimer)
- this.$wordHighlightTimer = setTimeout(function() {
- self.session.$mode.highlightSelection(self);
- self.$wordHighlightTimer = null;
- }, 30, this);
+ var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
};
diff --git a/lib/ace/search_highlight.js b/lib/ace/search_highlight.js
new file mode 100644
index 0000000..b2df779
--- /dev/null
+++ b/lib/ace/search_highlight.js
@@ -0,0 +1,3 @@
+new
+empty file

@ -1 +1 @@
Subproject commit 8bd16ba2eda6a1b0c6791f37d0803296ae37840f
Subproject commit d93670b47d776987b38bb2c31777c4e488338fac

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

@ -240,12 +240,9 @@ var BackgroundTokenizer = function(tokenizer, editor) {
var data = this.tokenizer.getLineTokens(line, state);
if (overflow) {
data.tokens.push(overflow);
data.state = null;
data.state = "start";
}
if (data.state == "start" && this.states[row] == null)
this.states[row] = "start";
if (this.states[row] !== data.state) {
this.states[row] = data.state;
this.lines[row + 1] = null;

View file

@ -0,0 +1,92 @@
/* ***** 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):
* Harutyun Amirjanyan <harutyun@c9.io>
*
* 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 ***** */
if (typeof process !== "undefined") {
require("amd-loader");
}
define(function(require, exports, module) {
"use strict";
var EditSession = require("./edit_session").EditSession;
var JavaScriptMode = require("./mode/javascript").Mode;
var Range = require("./range").Range;
var assert = require("./test/assertions");
function forceTokenize(session){
for (var i = 0, l = session.getLength(); i < l; i++)
session.getTokens(i)
}
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)
}
module.exports = {
"test background tokenizer update on session change" : function() {
var doc = new EditSession([
"/*",
"*/",
"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)
testStates(doc, ["comment", "comment"])
doc.insert({row:0, column:2}, "\n*/")
testStates(doc, [undefined, undefined, "comment"])
forceTokenize(doc)
testStates(doc, ["comment", "start", "start"])
}
};
});
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec()
}

View file

@ -51,16 +51,11 @@ oop.inherits(CommandManager, HashHandler);
if (editor && editor.$readOnly && !command.readOnly)
return false;
try {
var retvalue = this._emit("exec", {
editor: editor,
command: command,
args: args
});
} catch (e) {
window.console && window.console.log(e);
return true;
}
var retvalue = this._emit("exec", {
editor: editor,
command: command,
args: args
});
return retvalue === false ? false : true;
};

View file

@ -79,12 +79,15 @@ exports.defaultCommands = [{
exec: function(editor) { editor.selectMore(1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
readonly: true
}, {
}, {
name: "splitIntoLines",
exec: function(editor) { editor.multiSelect.splitIntoLines(); },
bindKey: {win: "Ctrl-Shift-L", mac: "Ctrl-Shift-L"},
readonly: true
}, {
}];
// commands active in multiselect mode
exports.multiSelectCommands = [{
name: "singleSelection",
bindKey: "esc",
exec: function(editor) { editor.exitMultiSelectMode(); },
@ -92,10 +95,7 @@ exports.defaultCommands = [{
isAvailable: function(editor) {return editor.inMultiSelectMode}
}];
// commands active in multiselect mode
exports.multiEditCommands = {"singleSelection": "esc"};
var HashHandler = require("../keyboard/hash_handler").HashHandler;
exports.keyboardHandler = new HashHandler(exports.multiEditCommands);
exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
});

View file

@ -55,14 +55,14 @@ var options = {
exports.get = function(key) {
if (!options.hasOwnProperty(key))
throw new Error("Unknown confik key: " + key);
throw new Error("Unknown config key: " + key);
return options[key];
};
exports.set = function(key, value) {
if (!options.hasOwnProperty(key))
throw new Error("Unknown confik key: " + key);
throw new Error("Unknown config key: " + key);
options[key] = value;
};

View file

@ -18,13 +18,6 @@
cursor: text;
}
.ace_composition {
position: absolute;
background: #555;
color: #DDD;
z-index: 4;
}
.ace_gutter {
position: absolute;
overflow : hidden;
@ -34,12 +27,6 @@
z-index: 4;
}
.ace_gutter_active_line {
position: absolute;
left: 0;
right: 0;
}
.ace_scroller.horscroll {
box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;
}
@ -95,8 +82,8 @@
height: 100%;
}
.ace_editor textarea {
position: fixed;
.ace_editor > textarea {
position: absolute;
z-index: 0;
width: 0.5em;
height: 1em;
@ -110,6 +97,15 @@
overflow: hidden;
}
.ace_editor > textarea.ace_composition {
background: #fff;
color: #000;
z-index: 1000;
opacity: 1;
border: solid lightgray 1px;
margin: -1px
}
.ace_layer {
z-index: 1;
position: absolute;
@ -196,13 +192,13 @@
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
display: inline-block;
height: 11px;
margin-top: -2px;
vertical-align: middle;
background-image:
background-image:
url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%11%00%00%00%09%08%06%00%00%00%D4%E8%C7%0C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li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V%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%B5IDAT(%15%A5%91%3D%0E%02!%10%85ac%E1%05%D6%CE%D6%C6%CE%D2%E8%ED%CD%DE%C0%C6%D6N.%E0V%F8%3D%9Ca%891XH%C2%BE%D9y%3F%90!%E6%9C%C3%BFk%E5%011%C6-%F5%C8N%04%DF%BD%FF%89%DFt%83DN%60%3E%F3%AB%A0%DE%1A%5Dg%BE%10Q%97%1B%40%9C%A8o%10%8F%5E%828%B4%1B%60%87%F6%02%26%85%1Ch%1E%C1%2B%5Bk%FF%86%EE%B7j%09%9A%DA%9B%ACe%A3%F9%EC%DA!9%B4%D5%A6%81%86%86%98%CC%3C%5B%40%FA%81%B3%E9%CB%23%94%C16Azo%05%D4%E1%C1%95a%3B%8A'%A0%E8%CC%17%22%85%1D%BA%00%A2%FA%DC%0A%94%D1%D1%8D%8B%3A%84%17B%C7%60%1A%25Z%FC%8D%00%00%00%00IEND%AEB%60%82"),
url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%007%08%06%00%00%00%C4%DD%80C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%D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AD.r%23%8E%C2%17%F5E%7C!%F0%BE3%BE%3E_%B7o%88a%A7%DB%BE%D3d%EB%A31Z%EB%BB%D3%91%BA%A2%B1z%94%8F%DB'%F6%3D%8E%AA%13%19%B2%B1%BE%B1~V%08%2B%B4%A2cjJ%B3tO%00%03%25mN%97%F3%05%93%EF%11%84%0B%7C%88%AE-%89%8F%ABbW%90O%2B%0Ao%99%0C%5E%97%0CI%AFH%D9.%B0%3B%8F%ED%03%B6S%D6%5D%E6i_s9%F3*p%E9%1B%FD%C3%EB.7U%06%5E%19%C0%D1s.%17%A03u%E4%09%B0%7C%5E%2C%EB%15%DB%1F%3C%9E%B7%80%91%3B%DBc%AD%3Dma%BA%8B%3EV%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%3AIDAT8%11c%FC%FF%FF%7F%18%03%1A%60%01%F2%3F%A0%891%80%04%FF%11-%F8%17%9BJ%E2%05%B1ZD%81v%26t%E7%80%F8%A3%82h%A12%1A%20%A3%01%02%0F%01%BA%25%06%00%19%C0%0D%AEF%D5%3ES%00%00%00%00IEND%AEB%60%82");
background-repeat: no-repeat, repeat-x;
@ -213,7 +209,7 @@
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
cursor: pointer;
pointer-events: auto;
}
@ -222,7 +218,7 @@
}
.ace_fold:hover{
background-image:
background-image:
url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%11%00%00%00%09%08%06%00%00%00%D4%E8%C7%0C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%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%B3%E9%CB%23%94%C16Azo%05%D4%E1%C1%95a%3B%8A'%A0%E8%CC%17%22%85%1D%BA%00%A2%FA%DC%0A%94%D1%D1%8D%8B%3A%84%17B%C7%60%1A%25Z%FC%8D%00%00%00%00IEND%AEB%60%82"),
url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%007%08%06%00%00%00%C4%DD%80C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li%E6%0B%03%89%9A%E6%D3%ED%F4P%92%B0%9F4%BF43Y%F3%E3%EDP%95%04%EB1%C5%F5%F6KF%F4%BA%BD%D7%DB%91%93%07%E35%3E%A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%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%003IDAT8%11c%FC%FF%FF%7F%3E%03%1A%60%01%F2%3F%A3%891%80%04%FFQ%26%F8w%C0%B43%A1%DB%0C%E2%8F%0A%A2%85%CAh%80%8C%06%08%3C%04%E8%96%18%00%A3S%0D%CD%CF%D8%C1%9D%00%00%00%00IEND%AEB%60%82");
background-repeat: no-repeat, repeat-x;
@ -247,7 +243,7 @@
height: 14px;
width: 11px;
vertical-align: text-bottom;
background-image: url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%00%05%08%06%00%00%00%8Do%26%E5%00%00%004IDATx%DAe%8A%B1%0D%000%0C%C2%F2%2CK%96%BC%D0%8F9%81%88H%E9%D0%0E%96%C0%10%92%3E%02%80%5E%82%E4%A9*-%EEsw%C8%CC%11%EE%96w%D8%DC%E9*Eh%0C%151(%00%00%00%00IEND%AEB%60%82");
background-repeat: no-repeat;
background-position: center 5px;
@ -292,23 +288,19 @@
}
.ace_fade-fold-widgets .ace_fold-widget {
-moz-transition: 0.5s opacity;
-webkit-transition: 0.5s opacity;
-o-transition: 0.5s opacity;
-ms-transition: 0.5s opacity;
transition: 0.5s opacity;
-moz-transition: opacity 0.4s ease 0.05s;
-webkit-transition: opacity 0.4s ease 0.05s;
-o-transition: opacity 0.4s ease 0.05s;
-ms-transition: opacity 0.4s ease 0.05s;
transition: opacity 0.4s ease 0.05s;
opacity: 0;
}
.ace_fade-fold-widgets:hover .ace_fold-widget {
-moz-transition-duration: 0.05s;
-webkit-transition-duration: 0.05s;
-o-transition-duration: 0.05s;
-ms-transition-duration: 0.05s;
transition-duration: 0.05s;
-moz-transition-delay: 0.2s;
-webkit-transition-delay: 0.2s;
-o-transition-delay: 0.2s;
-ms-transition-delay: 0.2s;
transition-delay: 0.2s;
-moz-transition: opacity 0.05s ease 0.05s;
-webkit-transition: opacity 0.05s ease 0.05s;
-o-transition: opacity 0.05s ease 0.05s;
-ms-transition: opacity 0.05s ease 0.05s;
transition: opacity 0.05s ease 0.05s;
opacity:1;
}

View file

@ -326,6 +326,13 @@ var Document = function(text) {
if (lines.length == 0)
return {row: row, column: 0};
// apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF)
// to circumvent that we have to break huge inserts into smaller chunks here
if (lines.length > 0xFFFF) {
var end = this.insertLines(row, lines.slice(0xFFFF));
lines = lines.slice(0, 0xFFFF);
}
var args = [row, 0];
args.push.apply(args, lines);
this.$lines.splice.apply(this.$lines, args);
@ -337,7 +344,7 @@ var Document = function(text) {
lines: lines
};
this._emit("change", { data: delta });
return range.end;
return end || range.end;
};
/**

View file

@ -51,6 +51,7 @@ var TextMode = require("./mode/text").Mode;
var Range = require("./range").Range;
var Document = require("./document").Document;
var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
var SearchHighlight = require("./search_highlight").SearchHighlight;
/**
* class EditSession
@ -307,6 +308,13 @@ var EditSession = function(text, mode) {
return token;
};
this.highlight = function(re) {
if (!this.$searchHighlight) {
var highlight = new SearchHighlight(null, "ace_selected_word", "text");
this.$searchHighlight = this.addDynamicMarker(highlight);
}
this.$searchHighlight.setRegexp(re);
}
/**
* EditSession.setUndoManager(undoManager)
* - undoManager (UndoManager): The new undo manager
@ -556,7 +564,8 @@ var EditSession = function(text, mode) {
type : type || "line",
renderer: typeof type == "function" ? type : null,
clazz : clazz,
inFront: !!inFront
inFront: !!inFront,
id: id
}
if (inFront) {
@ -570,6 +579,30 @@ var EditSession = function(text, mode) {
return id;
};
/**
* EditSession.addDynamicMarker(marker) -> {update}
* - marker : object with update method
* - inFront (Boolean): Set to `true` to establish a front marker
*
**/
this.addDynamicMarker = function(marker, inFront) {
if (!marker.update)
return;
var id = this.$markerId++;
marker.id = id;
marker.inFront = !!inFront;
if (inFront) {
this.$frontMarkers[id] = marker;
this._emit("changeFrontMarker")
} else {
this.$backMarkers[id] = marker;
this._emit("changeBackMarker")
}
return marker;
};
/**
* EditSession.removeMarker(markerId)
* - markerId (Number): A number representing a marker
@ -675,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) {
@ -1080,7 +1116,7 @@ var EditSession = function(text, mode) {
* {:Document.getTextRange.desc}
**/
this.getTextRange = function(range) {
return this.doc.getTextRange(range);
return this.doc.getTextRange(range || this.selection.getRange());
};
/** related to: Document.insert

View file

@ -235,6 +235,35 @@ var Editor = function(renderer, session) {
return this.session;
};
/** related to: Document.setValue
* Editor.setValue(val [,dontSelect]) -> String
* - val (String): The new value to set for the document
* - cursorPos (number): 0: selectAll, -1 document start, 1 end
*
* Sets the current document to `val`.
**/
this.setValue = function(val, cursorPos) {
this.session.doc.setValue(val);
if (!cursorPos)
this.selectAll();
else if (cursorPos == 1)
this.navigateFileEnd();
else if (cursorPos == -1)
this.navigateFileStart();
return val;
};
/** related to: EditSession.getValue
* Editor.getValue() -> String
*
* Returns the current session's content.
**/
this.getValue = function() {
return this.session.getValue();
};
/**
* Editor.getSelection() -> String
*
@ -249,8 +278,8 @@ var Editor = function(renderer, session) {
*
* {:VirtualRenderer.onResize}
**/
this.resize = function() {
this.renderer.onResize();
this.resize = function(force) {
this.renderer.onResize(force);
};
/**
@ -368,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");
@ -379,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");
@ -494,7 +529,7 @@ var Editor = function(renderer, session) {
* Emitted when a selection has changed.
**/
this.onSelectionChange = function(e) {
var session = this.getSession();
var session = this.session;
if (session.$selectionMarker) {
session.removeMarker(session.$selectionMarker);
@ -509,12 +544,40 @@ var Editor = function(renderer, session) {
this.$updateHighlightActiveLine();
}
var self = this;
if (this.$highlightSelectedWord && !this.$wordHighlightTimer)
this.$wordHighlightTimer = setTimeout(function() {
self.session.$mode.highlightSelection(self);
self.$wordHighlightTimer = null;
}, 30, this);
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
this.session.highlight(re);
};
this.$getSelectionHighLightRegexp = function() {
var session = this.session;
var selection = this.getSelectionRange();
if (selection.isEmpty() || selection.isMultiLine())
return;
var startOuter = selection.start.column - 1;
var endOuter = selection.end.column + 1;
var line = session.getLine(selection.start.row);
var lineCols = line.length;
var needle = line.substring(Math.max(startOuter, 0),
Math.min(endOuter, lineCols));
// Make sure the outer characters are not part of the word.
if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
(endOuter <= lineCols && /[\w\d]$/.test(needle)))
return;
needle = line.substring(selection.start.column, selection.end.column);
if (!/^[\w\d]+$/.test(needle))
return;
var re = this.$search.$assembleRegExp({
wholeWord: true,
caseSensitive: true,
needle: needle
});
return re;
};
/**
@ -541,7 +604,7 @@ var Editor = function(renderer, session) {
* Emitted when a breakpoint changes.
**/
this.onChangeBreakpoint = function() {
this.renderer.setBreakpoints(this.session.getBreakpoints());
this.renderer.updateBreakpoints();
};
/**
@ -888,7 +951,7 @@ var Editor = function(renderer, session) {
this.$highlightSelectedWord = true;
/**
* Editor.setHighlightSelectedWord(shouldHighlight)
* Editor.setHighlightSelectedWord(shouldHighlight)
* - shouldHighlight (Boolean): Set to `true` to highlight the currently selected word
*
* Determines if the currently selected word should be highlighted.
@ -898,20 +961,12 @@ var Editor = function(renderer, session) {
return;
this.$highlightSelectedWord = shouldHighlight;
if (shouldHighlight) {
this.session.getMode().highlightSelection(this);
} else {
this.session.getMode().clearSelectionHighlight(this);
if (this.$wordHighlightTimer) {
clearTimeout(this.$wordHighlightTimer);
this.$wordHighlightTimer = null;
}
}
this.$onSelectionChange();
};
/**
* Editor.getHighlightSelectedWord() -> Boolean
*
*
* Returns `true` if currently highlighted words are to be highlighted.
**/
this.getHighlightSelectedWord = function() {
@ -1954,65 +2009,84 @@ var Editor = function(renderer, session) {
};
/** related to: Search.find
* Editor.find(needle, options)
* - needle (String): The text to search for
* Editor.find(needle, options)
* - needle (String): The text to search for (optional)
* - options (Object): An object defining various search properties
* - animate (Boolean): If `true` animate scrolling
*
* Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]].
**/
this.find = function(needle, options, animate) {
this.clearSelection();
options = options || {};
options.needle = needle;
if (!options)
options = {};
if (typeof needle == "string" || needle instanceof RegExp)
options.needle = needle;
else if (typeof needle == "object")
oop.mixin(options, needle);
var range = this.selection.getRange();
if (options.needle == null) {
needle = this.session.getTextRange(range)
|| this.$search.$options.needle;
if (!needle) {
range = this.session.getWordRange(range.start.row, range.start.column);
needle = this.session.getTextRange(range);
}
this.$search.set({needle: needle});
}
this.$search.set(options);
this.$find(options.backwards, animate);
if (!options.start)
this.$search.set({start: range});
var newRange = this.$search.find(this.session);
if (options.preventScroll)
return newRange;
if (newRange) {
this.revealRange(newRange, animate);
return newRange;
}
// clear selection if nothing is found
if (options.backwards)
range.start = range.end;
else
range.end = range.start;
this.selection.setRange(range);
};
/** related to: Editor.find
* Editor.findNext(options)
* Editor.findNext(options)
* - options (Object): search options
* - animate (Boolean): If `true` animate scrolling
*
*
* Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
**/
this.findNext = function(options, animate) {
options = options || {};
this.$search.set(options);
this.$find(false, animate);
this.find({skipCurrent: true, backwards: false}, options, animate);
};
/** related to: Editor.find
* Editor.findPrevious(options)
* Editor.findPrevious(options)
* - options (Object): search options
* - animate (Boolean): If `true` animate scrolling
*
*
* Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
**/
this.findPrevious = function(options, animate) {
options = options || {};
this.$search.set(options);
this.$find(true, animate);
this.find(options, {skipCurrent: true, backwards: true}, animate);
};
this.$find = function(backwards, animate) {
if (!this.selection.isEmpty())
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
this.revealRange = function(range, animate) {
this.$blockScrolling += 1;
this.session.unfold(range);
this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;
if (typeof backwards != "undefined")
this.$search.set({backwards: backwards});
var range = this.$search.find(this.session);
if (range) {
this.$blockScrolling += 1;
this.session.unfold(range);
this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;
var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
if (animate != false)
this.renderer.animateScrolling(scrollTop);
}
};
/** related to: UndoManager.undo

View file

@ -70,6 +70,16 @@ var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"libero vehicula odio, eget bibendum mauris velit eu lorem.\n" +
"consectetur";
function callHighlighterUpdate(session, firstRow, lastRow) {
var rangeCount = 0;
var mockMarkerLayer = { drawSingleLineMarker: function() {rangeCount++;} }
session.$searchHighlight.update([], mockMarkerLayer, session, {
firstRow: firstRow,
lastRow: lastRow
});
return rangeCount;
}
module.exports = {
setUp: function(next) {
this.session = new EditSession(lipsum);
@ -87,55 +97,51 @@ module.exports = {
this.editor.moveCursorTo(0, 9);
this.selection.selectWord();
assert.ok(this.editor.$wordHighlightTimer != null);
this.session.$mode.highlightSelection(this.editor);
var highlighter = this.editor.session.$searchHighlight;
assert.ok(highlighter != null);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "ipsum");
assert.equal(this.session.$selectionOccurrences.length, 1);
assert.equal(highlighter.cache.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 2);
},
"test: highlight a word and clear highlight": function() {
this.editor.moveCursorTo(0, 8);
this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "ipsum");
assert.equal(this.session.$selectionOccurrences.length, 1);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 2);
this.session.getMode().clearSelectionHighlight(this.editor);
assert.equal(this.session.$selectionOccurrences.length, 0);
this.session.highlight("");
assert.equal(this.session.$searchHighlight.cache.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: highlight another word": function() {
this.selection.moveCursorTo(0, 14);
this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor");
assert.equal(this.session.$selectionOccurrences.length, 3);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 4);
},
"test: no selection, no highlight": function() {
this.selection.clearSelection();
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: select a word, no highlight": function() {
this.selection.moveCursorTo(0, 14);
this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
this.editor.setHighlightSelectedWord(false);
assert.ok(this.editor.$wordHighlightTimer == null);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor");
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: select a word with no matches": function() {
@ -156,32 +162,29 @@ module.exports = {
this.search.set(currentOptions);
this.selection.setSelectionRange(match);
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.getTextRange(match), "Mauris");
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 1);
},
"test: partial word selection 1": function() {
this.selection.moveCursorTo(0, 14);
this.selection.selectWord();
this.selection.selectLeft();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolo");
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: partial word selection 2": function() {
this.selection.moveCursorTo(0, 13);
this.selection.selectWord();
this.selection.selectRight();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor ");
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: partial word selection 3": function() {
@ -189,11 +192,10 @@ module.exports = {
this.selection.selectWord();
this.selection.selectLeft();
this.selection.shiftSelection(1);
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "olor");
assert.equal(this.session.$selectionOccurrences.length, 0);
assert.equal(callHighlighterUpdate(this.session, 0, 0), 0);
},
"test: select last word": function() {
@ -216,10 +218,9 @@ module.exports = {
this.search.set(currentOptions);
this.selection.setSelectionRange(match);
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.getTextRange(match), "consectetur");
assert.equal(this.session.$selectionOccurrences.length, 2);
assert.equal(callHighlighterUpdate(this.session, 0, 1), 3);
}
};

View file

@ -57,9 +57,8 @@ function HashHandler(config, platform) {
this.commands[command.name] = command;
if (command.bindKey) {
if (command.bindKey)
this._buildKeyHash(command);
}
};
this.removeCommand = function(command) {
@ -81,6 +80,10 @@ function HashHandler(config, platform) {
this.bindKey = function(key, command) {
if(!key)
return;
if (typeof command == "function") {
this.addCommand({exec: command, bindKey: key, name: key});
return;
}
var ckb = this.commmandKeyBinding;
key.split("|").forEach(function(keyPart) {

View file

@ -119,7 +119,8 @@ var KeyBinding = function(editor) {
else
success = toExecute.passEvent != true;
if (success && e)
// do not stop input events to not break repeating
if (success && e && hashId != -1)
event.stopEvent(e);
return success;

Some files were not shown because too many files have changed in this diff Show more