Compare commits

...
Sign in to create a new pull request.

45 commits

Author SHA1 Message Date
Fabian Jakobs
cb41085995 add refactor docs 2011-10-04 09:14:26 +02:00
Fabian Jakobs
85ed66edfe fix more unit tests 2011-08-17 14:36:35 +02:00
Fabian Jakobs
968db75cd8 add IE support 2011-08-17 10:27:56 +02:00
Fabian Jakobs
9d14042b37 only call the release capture handler once 2011-08-17 10:26:09 +02:00
Fabian Jakobs
22eb706b42 IE fix for the tokenizer 2011-08-17 10:25:06 +02:00
Fabian Jakobs
62904badce increase threshold for mouse wheel speed limiting 2011-08-17 10:24:41 +02:00
Fabian Jakobs
2f2cddd173 fix demo 2011-08-17 10:15:24 +02:00
Fabian Jakobs
ca4f8fb9b0 take care for excessive scroll speeds in safari 5.0 2011-08-17 09:31:25 +02:00
Fabian Jakobs
c372ec5c9a minor fixes 2011-08-17 09:31:25 +02:00
Fabian Jakobs
1b5c3b29ab move navigation code to the model and update some tests 2011-08-17 09:31:25 +02:00
Fabian Jakobs
3f53212c99 move layer update code into the window model 2011-08-17 09:30:33 +02:00
Fabian Jakobs
0ce6f734d4 move document into the model folder 2011-08-17 09:30:33 +02:00
Fabian Jakobs
f8bab3dbd5 flatten directory hierarchy by removing the
lib directory
2011-08-17 09:27:09 +02:00
Fabian Jakobs
776cf39d12 reorganize js worker code 2011-08-17 09:27:08 +02:00
Fabian Jakobs
133abb1d2d fix merge conflicts 2011-08-17 09:27:08 +02:00
Fabian Jakobs
085ffcf09d small fix 2011-08-17 09:27:07 +02:00
Fabian Jakobs
10b9ad34d5 remove unused code 2011-08-17 09:27:07 +02:00
Fabian Jakobs
606d1bdbaf detect chrome 2011-08-17 09:27:07 +02:00
Fabian Jakobs
6d40f616d5 move search code to the window model 2011-08-17 09:27:07 +02:00
Fabian Jakobs
cd42d284fd move resize handling in the window model 2011-08-17 09:24:42 +02:00
Fabian Jakobs
173d9ce7f7 move buffer listeners from editor.js to the
window controller.
2011-08-17 09:24:11 +02:00
Fabian Jakobs
3cf7ef9a61 no need to pass around the layer config anymore 2011-08-17 09:24:11 +02:00
Fabian Jakobs
82e2920599 don't use layerConfig.{lineHeight,characterHeight}
anymore
2011-08-17 09:23:31 +02:00
Fabian Jakobs
94b434d5e1 package 2011-08-17 09:23:31 +02:00
Fabian Jakobs
801cb923b7 move pilot code back into Ace 2011-08-17 09:21:35 +02:00
Fabian Jakobs
e96918892a computations involving pixels don't belong in the buffer 2011-08-17 09:20:15 +02:00
Fabian Jakobs
86f3fc2a1c move more scrolling code to the window model 2011-08-17 09:20:15 +02:00
Fabian Jakobs
d81d2858ad move more scroll stuff to the model 2011-08-17 09:20:15 +02:00
Fabian Jakobs
3c192c970b remove references to session 2011-08-17 09:20:15 +02:00
Fabian Jakobs
421e19ed78 treat horizontal scrolling just like vertical scrolling 2011-08-17 09:20:15 +02:00
Fabian Jakobs
1018f51b5e move visible row and cursor pixel position
calculation to the window model
2011-08-17 09:20:15 +02:00
Fabian Jakobs
e949f67df2 fix window view mock 2011-08-17 09:20:15 +02:00
Fabian Jakobs
8f8782701b move theme and text size to the window model 2011-08-17 09:19:32 +02:00
Fabian Jakobs
069293b3ff move horizontal scrollbar always visible setting to window model 2011-08-17 09:19:32 +02:00
Fabian Jakobs
1657ffb93e apply MVC to the virtual renderer. Split off all
state into the new WindowModel class and sync using
the new WindowController.
2011-08-17 09:19:32 +02:00
Fabian Jakobs
cca850a8a1 move window view mock into the "view" folder 2011-08-17 09:19:31 +02:00
Fabian Jakobs
a6ab658f15 move ui specific code into the view folder 2011-08-17 09:15:17 +02:00
Fabian Jakobs
0eb476e02f rename virtual_renderer to WindowView 2011-08-16 14:03:15 +02:00
Fabian Jakobs
89eeb3bd1a rename edit session to buffer 2011-08-16 14:01:49 +02:00
Fabian Jakobs
6808e3bb35 I can insert text again 2011-08-16 13:57:38 +02:00
Fabian Jakobs
a58da119b7 get rid of boot.js 2011-08-16 13:57:37 +02:00
Fabian Jakobs
c417dcd4e6 command_manager is no longer a singleton 2011-08-16 13:57:37 +02:00
Fabian Jakobs
8d0e1784e2 remove request argument to commands 2011-08-16 13:57:37 +02:00
Fabian Jakobs
3d011a8827 remove cockpit submodule 2011-08-16 13:57:37 +02:00
Fabian Jakobs
18ab9b4193 remove dependency on canon 2011-08-16 13:57:37 +02:00
247 changed files with 9804 additions and 15890 deletions

6
.gitmodules vendored
View file

@ -1,9 +1,3 @@
[submodule "support/cockpit"]
path = support/cockpit
url = git://github.com/ajaxorg/cockpit.git
[submodule "support/pilot"]
path = support/pilot
url = git://github.com/ajaxorg/pilot.git
[submodule "support/dryice"]
path = support/dryice
url = git://github.com/ajaxorg/dryice.git

View file

@ -79,8 +79,6 @@ var aceHome = __dirname;
console.log('# ace ---------');
var aceProject = [
aceHome + '/support/pilot/lib',
aceHome + '/lib',
aceHome
];
@ -127,10 +125,7 @@ copy({
source: [
copy.source.commonjs({
project: project,
require: [
"pilot/fixoldbrowsers",
"ace/ace"
]
require: ["ace/ace"]
})
],
filter: [ copy.filter.moduleDefines ],
@ -230,7 +225,7 @@ console.log('# ace themes ---------');
].forEach(function(theme) {
copy({
source: [{
root: aceHome + '/lib',
root: aceHome,
include: "ace/theme/" + theme + ".js"
}],
filter: modeThemeFilters,
@ -264,17 +259,16 @@ console.log('# ace worker ---------');
console.log("worker for " + mode + " mode");
var worker = copy.createDataObject();
var workerProject = copy.createCommonJsProject([
aceHome + '/support/pilot/lib',
aceHome + '/lib'
aceHome
]);
copy({
source: [
copy.source.commonjs({
project: workerProject,
require: [
'pilot/fixoldbrowsers',
'pilot/event_emitter',
'pilot/oop',
'ace/lib/fixoldbrowsers',
'ace/lib/event_emitter',
'ace/lib/oop',
'ace/mode/' + mode + '_worker'
]
})
@ -284,7 +278,7 @@ console.log('# ace worker ---------');
});
copy({
source: [
aceHome + "/lib/ace/worker/worker.js",
aceHome + "/ace/worker/worker.js",
worker
],
filter: [ copy.filter.uglifyjs, filterTextPlugin ],
@ -336,7 +330,7 @@ function demo() {
source: [
copy.source.commonjs({
project: project,
require: [ "pilot/index", "ace/defaults", "demo/boot" ]
require: [ "demo/demo" ]
})
],
filter: [ copy.filter.moduleDefines ],
@ -370,4 +364,4 @@ function demo() {
source: demo,
dest: 'build/demo/kitchen-sink-uncompressed.js'
});
}
}

View file

@ -37,41 +37,38 @@
define(function(require, exports, module) {
require("pilot/index");
require("pilot/fixoldbrowsers");
var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins([ "pilot/index" ]);
require("ace/lib/fixoldbrowsers");
var Dom = require("pilot/dom");
var Event = require("pilot/event");
var Dom = require("ace/lib/dom");
var Event = require("ace/lib/event");
var Editor = require("ace/editor").Editor;
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var Window = require("ace/model/window").Window;
var UndoManager = require("ace/undomanager").UndoManager;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var Renderer = require("ace/view/window_view").WindowView;
exports.edit = function(el) {
if (typeof(el) == "string") {
el = document.getElementById(el);
}
var doc = new EditSession(Dom.getInnerText(el));
var doc = new Buffer(Dom.getInnerText(el));
doc.setUndoManager(new UndoManager());
el.innerHTML = '';
var editor = new Editor(new Renderer(el, require("ace/theme/textmate")));
var theme = require("ace/theme/textmate");
var editor = new Editor(new Renderer(new Window(theme), el));
editor.setSession(doc);
var env = require("pilot/environment").create();
catalog.startupPlugins({ env: env }).then(function() {
env.document = doc;
env.editor = editor;
var env = {};
env.document = doc;
env.editor = editor;
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
Event.addListener(window, "resize", function() {
editor.resize();
});
el.env = env;
});
el.env = env;
// Store env on editor such that it can be accessed later on from
// the returned object.
editor.env = env;

View file

@ -37,8 +37,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var oop = require("ace/lib/oop");
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
/**
* An Anchor is a floating pointer in the document. Whenever text is inserted or

View file

@ -36,12 +36,12 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../support/paths");
require("../support/paths");
}
define(function(require, exports, module) {
var Document = require("ace/document").Document;
var Document = require("ace/model/document").Document;
var Anchor = require("ace/anchor").Anchor;
var Range = require("ace/range").Range;
var assert = require("ace/test/assertions");

View file

@ -37,8 +37,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var oop = require("ace/lib/oop");
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
var BackgroundTokenizer = function(tokenizer, editor) {
this.running = false;

View file

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

View file

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

View file

@ -40,27 +40,31 @@
define(function(require, exports, module) {
require("pilot/fixoldbrowsers");
require("ace/lib/fixoldbrowsers");
var oop = require("pilot/oop");
var event = require("pilot/event");
var lang = require("pilot/lang");
var useragent = require("pilot/useragent");
var oop = require("ace/lib/oop");
var event = require("ace/lib/event");
var lang = require("ace/lib/lang");
var useragent = require("ace/lib/useragent");
var TextInput = require("ace/keyboard/textinput").TextInput;
var MouseHandler = require("ace/mouse_handler").MouseHandler;
//var TouchHandler = require("ace/touch_handler").TouchHandler;
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var Window = require("ace/model/window").Window;
var WindowController = require("ace/window_controller").WindowController;
var Search = require("ace/search").Search;
var Range = require("ace/range").Range;
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
var CommandManager = require("ace/commands/command_manager").CommandManager;
var defaultCommands = require("ace/commands/default_commands").commands;
var Editor =function(renderer, session) {
var container = renderer.getContainerElement();
var Editor = function(windowView, buffer) {
var container = windowView.getContainerElement();
this.container = container;
this.renderer = renderer;
this.renderer = windowView;
this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
this.textInput = new TextInput(windowView.getTextAreaContainer(), this);
this.keyBinding = new KeyBinding(this);
// TODO detect touch event support
@ -70,12 +74,14 @@ var Editor =function(renderer, session) {
this.$mouseHandler = new MouseHandler(this);
}
this.$blockScrolling = 0;
this.$search = new Search().set({
this.windowModel = this.renderer.model;
this.windowModel.search = new Search().set({
wrap: true
});
this.windowController = new WindowController(this.windowModel, this.renderer);
this.setSession(session || new EditSession(""));
this.commands = new CommandManager(defaultCommands);
this.setSession(buffer || new Buffer(""));
};
(function(){
@ -114,93 +120,15 @@ var Editor =function(renderer, session) {
return this.keyBinding.getKeyboardHandler();
};
// TODO refactor
// remove
this.setSession = function(session) {
if (this.session == session)
return;
if (this.session) {
var oldSession = this.session;
this.session.removeEventListener("change", this.$onDocumentChange);
this.session.removeEventListener("changeMode", this.$onChangeMode);
this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
this.session.removeEventListener("onChangeFold", this.$onChangeFold);
this.session.removeEventListener("changeFrontMarker", this.$onChangeFrontMarker);
this.session.removeEventListener("changeBackMarker", this.$onChangeBackMarker);
this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
var selection = this.session.getSelection();
selection.removeEventListener("changeCursor", this.$onCursorChange);
selection.removeEventListener("changeSelection", this.$onSelectionChange);
this.session.setScrollTopRow(this.renderer.getScrollTopRow());
}
this.windowModel.setBuffer(session);
this.session = session;
this.$onDocumentChange = this.onDocumentChange.bind(this);
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onChangeMode = this.onChangeMode.bind(this);
session.addEventListener("changeMode", this.$onChangeMode);
this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
this.$onChangeTabSize = this.renderer.updateText.bind(this.renderer);
session.addEventListener("changeTabSize", this.$onChangeTabSize);
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
this.$onChangeFold = this.onChangeFold.bind(this);
session.addEventListener("changeFold", this.$onChangeFold);
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.selection = session.getSelection();
this.selection.addEventListener("changeCursor", this.$onCursorChange);
this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onChangeMode();
this.onCursorChange();
this.onSelectionChange();
this.onChangeFrontMarker();
this.onChangeBackMarker();
this.onChangeBreakpoint();
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.scrollToRow(session.getScrollTopRow());
this.renderer.updateFull();
this._dispatchEvent("changeSession", {
session: session,
oldSession: oldSession
});
};
this.getSession = function() {
@ -212,15 +140,16 @@ var Editor =function(renderer, session) {
};
this.resize = function() {
this.renderer.onResize();
//this.renderer.onResize();
this.windowController.resize();
};
this.setTheme = function(theme) {
this.renderer.setTheme(theme);
this.windowModel.setTheme(theme);
};
this.getTheme = function() {
return this.renderer.getTheme();
return this.windowModel.getTheme();
};
this.setStyle = function(style) {
@ -235,30 +164,6 @@ var Editor =function(renderer, session) {
this.container.style.fontSize = size;
};
this.$highlightBrackets = function() {
if (this.session.$bracketHighlight) {
this.session.removeMarker(this.session.$bracketHighlight);
this.session.$bracketHighlight = null;
}
if (this.$highlightPending) {
return;
}
// perform highlight async to not block the browser during navigation
var self = this;
this.$highlightPending = true;
setTimeout(function() {
self.$highlightPending = false;
var pos = self.session.findMatchingBracket(self.getCursorPosition());
if (pos) {
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
}
}, 10);
};
this.focus = function() {
// Safari needs the timeout
// iOS and Firefox need it called immediately
@ -290,117 +195,6 @@ var Editor =function(renderer, session) {
this._dispatchEvent("blur");
};
this.onDocumentChange = function(e) {
var delta = e.data;
var range = delta.range;
if (range.start.row == range.end.row && delta.action != "insertLines" && delta.action != "removeLines")
var lastRow = range.end.row;
else
lastRow = Infinity;
this.renderer.updateLines(range.start.row, lastRow);
// update cursor because tab characters can influence the cursor position
this.renderer.updateCursor();
};
this.onTokenizerUpdate = function(e) {
var rows = e.data;
this.renderer.updateLines(rows.first, rows.last);
};
this.onCursorChange = function(e) {
this.renderer.updateCursor();
if (!this.$blockScrolling) {
this.renderer.scrollCursorIntoView();
}
// move text input over the cursor
// this is required for iOS and IME
this.renderer.moveTextAreaToCursor(this.textInput.getElement());
this.$highlightBrackets();
this.$updateHighlightActiveLine();
};
this.$updateHighlightActiveLine = function() {
var session = this.getSession();
if (session.$highlightLineMarker) {
session.removeMarker(session.$highlightLineMarker);
}
session.$highlightLineMarker = null;
if (this.getHighlightActiveLine() && (this.getSelectionStyle() != "line" || !this.selection.isMultiLine())) {
var cursor = this.getCursorPosition(),
foldLine = this.session.getFoldLine(cursor.row);
var range;
if (foldLine) {
range = new Range(foldLine.start.row, 0, foldLine.end.row + 1, 0);
} else {
range = new Range(cursor.row, 0, cursor.row+1, 0);
}
session.$highlightLineMarker = session.addMarker(range, "ace_active_line", "background");
}
};
this.onSelectionChange = function(e) {
var session = this.getSession();
if (session.$selectionMarker) {
session.removeMarker(session.$selectionMarker);
}
session.$selectionMarker = null;
if (!this.selection.isEmpty()) {
var range = this.selection.getRange();
var style = this.getSelectionStyle();
session.$selectionMarker = session.addMarker(range, "ace_selection", style);
} else {
this.$updateHighlightActiveLine();
}
if (this.$highlightSelectedWord)
this.session.getMode().highlightSelection(this);
};
this.onChangeFrontMarker = function() {
this.renderer.updateFrontMarkers();
};
this.onChangeBackMarker = function() {
this.renderer.updateBackMarkers();
};
this.onChangeBreakpoint = function() {
this.renderer.setBreakpoints(this.session.getBreakpoints());
};
this.onChangeAnnotation = function() {
this.renderer.setAnnotations(this.session.getAnnotations());
};
this.onChangeMode = function() {
this.renderer.updateText()
};
this.onChangeWrapLimit = function() {
this.renderer.updateFull();
};
this.onChangeWrapMode = function() {
this.renderer.onResize(true);
};
this.onChangeFold = function() {
// Update the active line marker as due to folding changes the current
// line range on the screen might have changed.
this.$updateHighlightActiveLine();
// TODO: This might be too much updating. Okay for now.
this.renderer.updateFull();
};
this.getCopyText = function() {
var text = "";
if (!this.selection.isEmpty())
@ -520,13 +314,10 @@ var Editor =function(renderer, session) {
}
};
this.onTextInput = function(text, notPasted) {
if (!notPasted)
this._emit("paste", text);
// In case the text was not pasted and we got only one character, then
this.onTextInput = function(text) {
// In case we got only one character, then
// handel it as a command key stroke.
if (notPasted && text.length == 1) {
if (text.length == 1) {
// Note: The `null` as `keyCode` is important here, as there are
// some checks in the code for `keyCode == 0` meaning the text comes
// from the keyBinding.onTextInput code path.
@ -546,6 +337,11 @@ var Editor =function(renderer, session) {
}
};
this.onPaste = function(text) {
this._emit("paste", text);
this.keyBinding.onTextInput(text);
};
this.onCommandKey = function(e, hashId, keyCode) {
this.keyBinding.onCommandKey(e, hashId, keyCode);
};
@ -570,72 +366,68 @@ var Editor =function(renderer, session) {
return this.$mouseHandler.getScrollSpeed()
};
this.$selectionStyle = "line";
this.setSelectionStyle = function(style) {
if (this.$selectionStyle == style) return;
this.$selectionStyle = style;
this.onSelectionChange();
this._dispatchEvent("changeSelectionStyle", {data: style});
this.windowModel.setSelectionStyle(style);
};
this.getSelectionStyle = function() {
return this.$selectionStyle;
return this.windowModel.getSelectionStyle();
};
this.$highlightActiveLine = true;
this.setHighlightActiveLine = function(shouldHighlight) {
if (this.$highlightActiveLine == shouldHighlight) return;
this.$highlightActiveLine = shouldHighlight;
this.$updateHighlightActiveLine();
this.windowModel.setHighlightActiveLine(shouldHighlight);
};
this.getHighlightActiveLine = function() {
return this.$highlightActiveLine;
return this.windowModel.getHighlightActiveLine();
};
this.$highlightSelectedWord = true;
this.setHighlightSelectedWord = function(shouldHighlight) {
if (this.$highlightSelectedWord == shouldHighlight)
return;
this.$highlightSelectedWord = shouldHighlight;
if (shouldHighlight)
this.session.getMode().highlightSelection(this);
else
this.session.getMode().clearSelectionHighlight(this);
this.windowModel.setHighlightSelectedWord(shouldHighlight);
};
this.getHighlightSelectedWord = function() {
return this.$highlightSelectedWord;
return this.windowModel.getHighlightSelectedWord();
};
this.setShowInvisibles = function(showInvisibles) {
if (this.getShowInvisibles() == showInvisibles)
return;
this.renderer.setShowInvisibles(showInvisibles);
this.windowModel.setShowInvisibles(showInvisibles);
};
this.getShowInvisibles = function() {
return this.renderer.getShowInvisibles();
return this.windowModel.getShowInvisibles();
};
this.setShowPrintMargin = function(showPrintMargin) {
this.renderer.setShowPrintMargin(showPrintMargin);
this.windowModel.setShowPrintMargin(showPrintMargin);
};
this.getShowPrintMargin = function() {
return this.renderer.getShowPrintMargin();
return this.windowModel.getShowPrintMargin();
};
this.setPrintMarginColumn = function(showPrintMargin) {
this.renderer.setPrintMarginColumn(showPrintMargin);
this.windowModel.setPrintMarginColumn(showPrintMargin);
};
this.getPrintMarginColumn = function() {
return this.renderer.getPrintMarginColumn();
return this.windowModel.getPrintMarginColumn();
};
this.setShowGutter = function(showGutter) {
this.windowModel.setShowGutter(showGutter);
};
this.getShowGutter = function() {
return this.windowModel.getShowGutter();
};
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
this.windowModel.setHScrollBarAlwaysVisible(alwaysVisible);
};
this.getHScrollBarAlwaysVisible = function() {
return this.windowModel.getHScrollBarAlwaysVisible();
};
this.$readOnly = false;
@ -914,32 +706,28 @@ var Editor =function(renderer, session) {
this.renderer.hideComposition();
};
this.getFirstVisibleRow = function() {
return this.renderer.getFirstVisibleRow();
return this.windowModel.getFirstVisibleRow();
};
this.getLastVisibleRow = function() {
return this.renderer.getLastVisibleRow();
return this.windowModel.getLastVisibleRow();
};
this.isRowVisible = function(row) {
return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
return this.windowModel.isRowVisible(row);
};
this.$getVisibleRowCount = function() {
return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
return this.windowModel.getVisibleRowCount();
};
this.$getPageDownRow = function() {
return this.renderer.getScrollBottomRow();
return this.windowModel.getPageDownRow();
};
this.$getPageUpRow = function() {
var firstRow = this.renderer.getScrollTopRow();
var lastRow = this.renderer.getScrollBottomRow();
return firstRow - (lastRow - firstRow);
return this.windowModel.getPageUpRow();
};
this.selectPageDown = function() {
@ -954,7 +742,7 @@ var Editor =function(renderer, session) {
};
this.selectPageUp = function() {
var visibleRows = this.renderer.getScrollTopRow() - this.renderer.getScrollBottomRow();
var visibleRows = this.windowModel.getScrollTopRow() - this.windowModel.getScrollBottomRow();
var row = this.$getPageUpRow() + Math.round(visibleRows / 2);
this.scrollPageUp();
@ -986,228 +774,120 @@ var Editor =function(renderer, session) {
};
this.scrollPageUp = function() {
this.renderer.scrollToRow(this.$getPageUpRow());
this.windowModel.scrollToRow(this.$getPageUpRow());
};
this.scrollToRow = function(row) {
this.renderer.scrollToRow(row);
this.windowModel.scrollToRow(row);
};
this.scrollToLine = function(line, center) {
this.renderer.scrollToLine(line, center);
this.windowModel.scrollToLine(line, center);
};
this.centerSelection = function() {
var range = this.getSelectionRange();
var line = Math.floor(range.start.row + (range.end.row - range.start.row) / 2);
this.renderer.scrollToLine(line, true);
this.windowModel.centerSelection();
};
this.getCursorPosition = function() {
return this.selection.getCursor();
return this.windowModel.getCursorPosition();
};
this.getCursorPositionScreen = function() {
return this.session.documentToScreenPosition(this.getCursorPosition());
return this.windowModel.getCursorPositionScreen();
};
this.getSelectionRange = function() {
return this.selection.getRange();
return this.windowModel.getSelectionRange();
};
this.selectAll = function() {
this.$blockScrolling += 1;
this.selection.selectAll();
this.$blockScrolling -= 1;
this.windowModel.selectAll();
};
this.clearSelection = function() {
this.selection.clearSelection();
this.windowModel.clearSelection();
};
this.moveCursorTo = function(row, column) {
this.selection.moveCursorTo(row, column);
this.windowModel.moveCursorTo(row, column);
};
this.moveCursorToPosition = function(pos) {
this.selection.moveCursorToPosition(pos);
this.windowModel.moveCursorToPosition(pos);
};
this.gotoLine = function(lineNumber, column) {
this.selection.clearSelection();
this.$blockScrolling += 1;
this.moveCursorTo(lineNumber-1, column || 0);
this.$blockScrolling -= 1;
if (!this.isRowVisible(this.getCursorPosition().row)) {
this.scrollToLine(lineNumber, true);
}
},
this.windowModel.gotoLine(lineNumber, column);
};
this.navigateTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
this.windowModel.navigateTo(row, column);
};
this.navigateUp = function(times) {
this.selection.clearSelection();
times = times || 1;
this.selection.moveCursorBy(-times, 0);
this.windowModel.navigateUp(times);
};
this.navigateDown = function(times) {
this.selection.clearSelection();
times = times || 1;
this.selection.moveCursorBy(times, 0);
this.windowModel.navigateDown(times);
};
this.navigateLeft = function(times) {
if (!this.selection.isEmpty()) {
var selectionStart = this.getSelectionRange().start;
this.moveCursorToPosition(selectionStart);
}
else {
times = times || 1;
while (times--) {
this.selection.moveCursorLeft();
}
}
this.clearSelection();
this.windowModel.navigateLeft(times);
};
this.navigateRight = function(times) {
if (!this.selection.isEmpty()) {
var selectionEnd = this.getSelectionRange().end;
this.moveCursorToPosition(selectionEnd);
}
else {
times = times || 1;
while (times--) {
this.selection.moveCursorRight();
}
}
this.clearSelection();
this.windowModel.navigateRight(times);
};
this.navigateLineStart = function() {
this.selection.moveCursorLineStart();
this.clearSelection();
this.windowModel.navigateLineStart()
};
this.navigateLineEnd = function() {
this.selection.moveCursorLineEnd();
this.clearSelection();
this.windowModel.navigateLineEnd();
};
this.navigateFileEnd = function() {
this.selection.moveCursorFileEnd();
this.clearSelection();
this.windowModel.navigateFileEnd();
};
this.navigateFileStart = function() {
this.selection.moveCursorFileStart();
this.clearSelection();
this.windowModel.navigateFileStart();
};
this.navigateWordRight = function() {
this.selection.moveCursorWordRight();
this.clearSelection();
this.windowModel.navigateWordRight();
};
this.navigateWordLeft = function() {
this.selection.moveCursorWordLeft();
this.clearSelection();
this.windowModel.navigateWordLeft();
};
this.replace = function(replacement, options) {
if (options)
this.$search.set(options);
var range = this.$search.find(this.session);
if (!range)
return;
this.$tryReplace(range, replacement);
if (range !== null)
this.selection.setSelectionRange(range);
},
this.windowModel.replace(replace, options);
};
this.replaceAll = function(replacement, options) {
if (options) {
this.$search.set(options);
}
var ranges = this.$search.findAll(this.session);
if (!ranges.length)
return;
var selection = this.getSelectionRange();
this.clearSelection();
this.selection.moveCursorTo(0, 0);
this.$blockScrolling += 1;
for (var i = ranges.length - 1; i >= 0; --i)
this.$tryReplace(ranges[i], replacement);
this.selection.setSelectionRange(selection);
this.$blockScrolling -= 1;
},
this.$tryReplace = function(range, replacement) {
var input = this.session.getTextRange(range);
var replacement = this.$search.replace(input, replacement);
if (replacement !== null) {
range.end = this.session.replace(range, replacement);
return range;
} else {
return null;
}
this.windowModel.replaceAll(replaceAll, options);
};
this.getLastSearchOptions = function() {
return this.$search.getOptions();
return this.windowModel.getLastSearchOptions();
};
this.find = function(needle, options) {
this.clearSelection();
options = options || {};
options.needle = needle;
this.$search.set(options);
this.$find();
},
this.windowModel.find(needle, options);
};
this.findNext = function(options) {
options = options || {};
if (typeof options.backwards == "undefined")
options.backwards = false;
this.$search.set(options);
this.$find();
this.windowModel.findNext(options);
};
this.findPrevious = function(options) {
options = options || {};
if (typeof options.backwards == "undefined")
options.backwards = true;
this.$search.set(options);
this.$find();
};
this.$find = function(backwards) {
if (!this.selection.isEmpty()) {
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
}
if (typeof backwards != "undefined")
this.$search.set({backwards: backwards});
var range = this.$search.find(this.session);
if (range) {
this.gotoLine(range.end.row+1, range.end.column);
this.selection.setSelectionRange(range);
}
this.windowModel.findPrevious(options);
};
this.undo = function() {

View file

@ -36,23 +36,23 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../support/paths");
require("../support/paths");
require("ace/test/mockdom");
}
define(function(require, exports, module) {
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var Editor = require("ace/editor").Editor;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var UndoManager = require("ace/undomanager").UndoManager;
var MockRenderer = require("ace/test/mockrenderer").MockRenderer;
var WindowViewMock = require("ace/view/window_view_mock").WindowViewMock;
var assert = require("ace/test/assertions");
module.exports = {
"test: delete line from the middle" : function() {
var session = new EditSession(["a", "b", "c", "d"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a", "b", "c", "d"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.removeLines();
@ -77,8 +77,8 @@ module.exports = {
},
"test: delete multiple selected lines" : function() {
var session = new EditSession(["a", "b", "c", "d"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a", "b", "c", "d"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.getSelection().selectDown();
@ -89,8 +89,8 @@ module.exports = {
},
"test: delete first line" : function() {
var session = new EditSession(["a", "b", "c"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a", "b", "c"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.removeLines();
@ -99,8 +99,8 @@ module.exports = {
},
"test: delete last should also delete the new line of the previous line" : function() {
var session = new EditSession(["a", "b", "c", ""].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a", "b", "c", ""].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(3, 0);
@ -114,8 +114,8 @@ module.exports = {
},
"test: indent block" : function() {
var session = new EditSession(["a12345", "b12345", "c12345"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a12345", "b12345", "c12345"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 3);
editor.getSelection().selectDown();
@ -132,8 +132,8 @@ module.exports = {
},
"test: indent selected lines" : function() {
var session = new EditSession(["a12345", "b12345", "c12345"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["a12345", "b12345", "c12345"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 0);
editor.getSelection().selectDown();
@ -143,8 +143,8 @@ module.exports = {
},
"test: no auto indent if cursor is before the {" : function() {
var session = new EditSession("{", new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer("{", new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 0);
editor.onTextInput("\n");
@ -152,8 +152,8 @@ module.exports = {
},
"test: outdent block" : function() {
var session = new EditSession([" a12345", " b12345", " c12345"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer([" a12345", " b12345", " c12345"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 5);
editor.getSelection().selectDown();
@ -177,8 +177,8 @@ module.exports = {
},
"test: outent without a selection should update cursor" : function() {
var session = new EditSession(" 12");
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(" 12");
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 3);
editor.blockOutdent(" ");
@ -188,8 +188,8 @@ module.exports = {
},
"test: comment lines should perserve selection" : function() {
var session = new EditSession([" abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer([" abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 2);
editor.getSelection().selectDown();
@ -203,8 +203,8 @@ module.exports = {
},
"test: uncomment lines should perserve selection" : function() {
var session = new EditSession(["// abc", "//cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["// abc", "//cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 1);
editor.getSelection().selectDown();
@ -218,8 +218,8 @@ module.exports = {
},
"test: toggle comment lines twice should return the original text" : function() {
var session = new EditSession([" abc", "cde", "fg"], new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer([" abc", "cde", "fg"], new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 0);
editor.getSelection().selectDown();
@ -234,8 +234,8 @@ module.exports = {
"test: comment lines - if the selection end is at the line start it should stay there": function() {
//select down
var session = new EditSession(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 0);
editor.getSelection().selectDown();
@ -244,8 +244,8 @@ module.exports = {
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
// select up
var session = new EditSession(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 0);
editor.getSelection().selectUp();
@ -255,8 +255,8 @@ module.exports = {
},
"test: move lines down should select moved lines" : function() {
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(0, 1);
editor.getSelection().selectDown();
@ -282,8 +282,8 @@ module.exports = {
},
"test: move lines up should select moved lines" : function() {
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(2, 1);
editor.getSelection().selectDown();
@ -303,8 +303,8 @@ module.exports = {
"test: move line without active selection should move cursor to start of the moved line" : function()
{
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.clearSelection();
@ -321,8 +321,8 @@ module.exports = {
},
"test: copy lines down should select lines and place cursor at the selection start" : function() {
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.getSelection().selectDown();
@ -336,8 +336,8 @@ module.exports = {
},
"test: copy lines up should select lines and place cursor at the selection start" : function() {
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer(["11", "22", "33", "44"].join("\n"));
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.getSelection().selectDown();
@ -351,8 +351,8 @@ module.exports = {
},
"test: input a tab with soft tab should convert it to spaces" : function() {
var session = new EditSession("");
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer("");
var editor = new Editor(new WindowViewMock(), session);
session.setTabSize(2);
session.setUseSoftTabs(true);
@ -366,8 +366,8 @@ module.exports = {
},
"test: input tab without soft tabs should keep the tab character" : function() {
var session = new EditSession("");
var editor = new Editor(new MockRenderer(), session);
var session = new Buffer("");
var editor = new Editor(new WindowViewMock(), session);
session.setUseSoftTabs(false);
@ -376,12 +376,12 @@ module.exports = {
},
"test: undo/redo for delete line" : function() {
var session = new EditSession(["111", "222", "333"]);
var session = new Buffer(["111", "222", "333"]);
var undoManager = new UndoManager();
session.setUndoManager(undoManager);
var initialText = session.toString();
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.removeLines();
var step1 = session.toString();
@ -416,38 +416,38 @@ module.exports = {
},
"test: remove left should remove character left of the cursor" : function() {
var session = new EditSession(["123", "456"]);
var session = new Buffer(["123", "456"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.removeLeft();
assert.equal(session.toString(), "123\n56");
},
"test: remove left should remove line break if cursor is at line start" : function() {
var session = new EditSession(["123", "456"]);
var session = new Buffer(["123", "456"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 0);
editor.removeLeft();
assert.equal(session.toString(), "123456");
},
"test: remove left should remove tabsize spaces if cursor is on a tab stop and preceeded by spaces" : function() {
var session = new EditSession(["123", " 456"]);
var session = new Buffer(["123", " 456"]);
session.setUseSoftTabs(true);
session.setTabSize(4);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 8);
editor.removeLeft();
assert.equal(session.toString(), "123\n 456");
},
"test: transpose at line start should be a noop": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 0);
editor.transposeLetters();
@ -455,9 +455,9 @@ module.exports = {
},
"test: transpose in line should swap the charaters before and after the cursor": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 2);
editor.transposeLetters();
@ -465,9 +465,9 @@ module.exports = {
},
"test: transpose at line end should swap the last two characters": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 4);
editor.transposeLetters();
@ -475,9 +475,9 @@ module.exports = {
},
"test: transpose with non empty selection should be a noop": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 1);
editor.getSelection().selectRight();
editor.transposeLetters();
@ -486,27 +486,27 @@ module.exports = {
},
"test: transpose should move the cursor behind the last swapped character": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 2);
editor.transposeLetters();
assert.position(editor.getCursorPosition(), 1, 3);
},
"test: remove to line end": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 2);
editor.removeToLineEnd();
assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
},
"test: remove to line end at line end should remove the new line": function() {
var session = new EditSession(["123", "4567", "89"]);
var session = new Buffer(["123", "4567", "89"]);
var editor = new Editor(new MockRenderer(), session);
var editor = new Editor(new WindowViewMock(), session);
editor.moveCursorTo(1, 4);
editor.removeToLineEnd();
assert.position(editor.getCursorPosition(), 1, 4);

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var keyUtil = require("pilot/keys");
var keyUtil = require("ace/lib/keys");
function HashHandler(config) {
this.setConfig(config);

View file

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

View file

@ -39,9 +39,9 @@
define(function(require, exports, module) {
var event = require("pilot/event");
var useragent = require("pilot/useragent");
var dom = require("pilot/dom");
var event = require("ace/lib/event");
var useragent = require("ace/lib/useragent");
var dom = require("ace/lib/dom");
var TextInput = function(parentNode, host) {
@ -67,13 +67,14 @@ var TextInput = function(parentNode, host) {
if (!copied) {
var value = valueToSend || text.value;
if (value) {
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0))
value = value.slice(0, -1);
if (value)
host.onTextInput(value, !pasted);
}
else {
host.onTextInput(value, !pasted);
if (value) {
if (pasted)
host.onPaste(value);
else
host.onTextInput(value);
}
// If editor is no longer focused we quit immediately, since

103
ace/lib/browser_focus.js Normal file
View file

@ -0,0 +1,103 @@
/* 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):
* Fabian Jakobs <fabian AT ajax DOT org>
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
* Julian Viereck <julian.viereck@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var oop = require("ace/lib/oop");
var event = require("ace/lib/event");
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
/**
* This class keeps track of the focus state of the given window.
* Focus changes for example when the user switches a browser tab,
* goes to the location bar or switches to another application.
*/
var BrowserFocus = function(win) {
win = win || window;
this.lastFocus = new Date().getTime();
this._isFocused = true;
var _self = this;
// IE < 9 supports focusin and focusout events
if ("onfocusin" in win.document) {
event.addListener(win.document, "focusin", function(e) {
_self._setFocused(true);
});
event.addListener(win.document, "focusout", function(e) {
_self._setFocused(!!e.toElement);
});
}
else {
event.addListener(win, "blur", function(e) {
_self._setFocused(false);
});
event.addListener(win, "focus", function(e) {
_self._setFocused(true);
});
}
};
(function(){
oop.implement(this, EventEmitter);
this.isFocused = function() {
return this._isFocused;
};
this._setFocused = function(isFocused) {
if (this._isFocused == isFocused)
return;
if (isFocused)
this.lastFocus = new Date().getTime();
this._isFocused = isFocused;
this._emit("changeFocus");
};
}).call(BrowserFocus.prototype);
exports.BrowserFocus = BrowserFocus;
});

263
ace/lib/dom.js Normal file
View file

@ -0,0 +1,263 @@
/* 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):
* Fabian Jakobs <fabian AT ajax DOT org>
* Mihai Sucan <mihai AT sucan AT gmail ODT com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var XHTML_NS = "http://www.w3.org/1999/xhtml";
exports.createElement = function(tag, ns) {
return document.createElementNS ?
document.createElementNS(ns || XHTML_NS, tag) :
document.createElement(tag);
};
exports.setText = function(elem, text) {
if (elem.innerText !== undefined) {
elem.innerText = text;
}
if (elem.textContent !== undefined) {
elem.textContent = text;
}
};
if (!document.documentElement.classList) {
exports.hasCssClass = function(el, name) {
var classes = el.className.split(/\s+/g);
return classes.indexOf(name) !== -1;
};
/**
* Add a CSS class to the list of classes on the given node
*/
exports.addCssClass = function(el, name) {
if (!exports.hasCssClass(el, name)) {
el.className += " " + name;
}
};
/**
* Remove a CSS class from the list of classes on the given node
*/
exports.removeCssClass = function(el, name) {
var classes = el.className.split(/\s+/g);
while (true) {
var index = classes.indexOf(name);
if (index == -1) {
break;
}
classes.splice(index, 1);
}
el.className = classes.join(" ");
};
exports.toggleCssClass = function(el, name) {
var classes = el.className.split(/\s+/g), add = true;
while (true) {
var index = classes.indexOf(name);
if (index == -1) {
break;
}
add = false;
classes.splice(index, 1);
}
if(add)
classes.push(name);
el.className = classes.join(" ");
return add;
};
} else {
exports.hasCssClass = function(el, name) {
return el.classList.contains(name);
};
exports.addCssClass = function(el, name) {
el.classList.add(name);
};
exports.removeCssClass = function(el, name) {
el.classList.remove(name);
};
exports.toggleCssClass = function(el, name) {
return el.classList.toggle(name);
};
}
/**
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
exports.setCssClass = function(node, className, include) {
if (include) {
exports.addCssClass(node, className);
} else {
exports.removeCssClass(node, className);
}
};
exports.importCssString = function(cssText, doc){
doc = doc || document;
if (doc.createStyleSheet) {
var sheet = doc.createStyleSheet();
sheet.cssText = cssText;
}
else {
var style = doc.createElementNS ?
doc.createElementNS(XHTML_NS, "style") :
doc.createElement("style");
style.appendChild(doc.createTextNode(cssText));
var head = doc.getElementsByTagName("head")[0] || doc.documentElement;
head.appendChild(style);
}
};
exports.getInnerWidth = function(element) {
return (parseInt(exports.computedStyle(element, "paddingLeft"))
+ parseInt(exports.computedStyle(element, "paddingRight")) + element.clientWidth);
};
exports.getInnerHeight = function(element) {
return (parseInt(exports.computedStyle(element, "paddingTop"))
+ parseInt(exports.computedStyle(element, "paddingBottom")) + element.clientHeight);
};
if (window.pageYOffset !== undefined) {
exports.getPageScrollTop = function() {
return window.pageYOffset;
};
exports.getPageScrollLeft = function() {
return window.pageXOffset;
};
}
else {
exports.getPageScrollTop = function() {
return document.body.scrollTop;
};
exports.getPageScrollLeft = function() {
return document.body.scrollLeft;
};
}
if (window.getComputedStyle)
exports.computedStyle = function(element, style) {
if (style)
return (window.getComputedStyle(element, "") || {})[style] || "";
return window.getComputedStyle(element, "") || {}
};
else
exports.computedStyle = function(element, style) {
if (style)
return element.currentStyle[style];
return element.currentStyle
};
exports.scrollbarWidth = function() {
var inner = exports.createElement("p");
inner.style.width = "100%";
inner.style.minWidth = "0px";
inner.style.height = "200px";
var outer = exports.createElement("div");
var style = outer.style;
style.position = "absolute";
style.left = "-10000px";
style.overflow = "hidden";
style.width = "200px";
style.minWidth = "0px";
style.height = "150px";
outer.appendChild(inner);
var body = document.body || document.documentElement;
body.appendChild(outer);
var noScrollbar = inner.offsetWidth;
style.overflow = "scroll";
var withScrollbar = inner.offsetWidth;
if (noScrollbar == withScrollbar) {
withScrollbar = outer.clientWidth;
}
body.removeChild(outer);
return noScrollbar-withScrollbar;
};
/**
* Optimized set innerHTML. This is faster than plain innerHTML if the element
* already contains a lot of child elements.
*
* See http://blog.stevenlevithan.com/archives/faster-than-innerhtml for details
*/
exports.setInnerHtml = function(el, innerHtml) {
var element = el.cloneNode(false);//document.createElement("div");
element.innerHTML = innerHtml;
el.parentNode.replaceChild(element, el);
return element;
};
exports.setInnerText = function(el, innerText) {
if (document.body && "textContent" in document.body)
el.textContent = innerText;
else
el.innerText = innerText;
};
exports.getInnerText = function(el) {
if (document.body && "textContent" in document.body)
return el.textContent;
else
return el.innerText || el.textContent || "";
};
exports.getParentWindow = function(document) {
return document.defaultView || document.parentWindow;
};
});

325
ace/lib/event.js Normal file
View file

@ -0,0 +1,325 @@
/* ***** 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):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var keys = require("ace/lib/keys");
var useragent = require("ace/lib/useragent");
var dom = require("ace/lib/dom");
exports.addListener = function(elem, type, callback) {
if (elem.addEventListener) {
return elem.addEventListener(type, callback, false);
}
if (elem.attachEvent) {
var wrapper = function() {
callback(window.event);
};
callback._wrapper = wrapper;
elem.attachEvent("on" + type, wrapper);
}
};
exports.removeListener = function(elem, type, callback) {
if (elem.removeEventListener) {
return elem.removeEventListener(type, callback, false);
}
if (elem.detachEvent) {
elem.detachEvent("on" + type, callback._wrapper || callback);
}
};
/**
* Prevents propagation and clobbers the default action of the passed event
*/
exports.stopEvent = function(e) {
exports.stopPropagation(e);
exports.preventDefault(e);
return false;
};
exports.stopPropagation = function(e) {
if (e.stopPropagation)
e.stopPropagation();
else
e.cancelBubble = true;
};
exports.preventDefault = function(e) {
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
};
exports.getDocumentX = function(e) {
if (e.clientX) {
return e.clientX + dom.getPageScrollLeft();
} else {
return e.pageX;
}
};
exports.getDocumentY = function(e) {
if (e.clientY) {
return e.clientY + dom.getPageScrollTop();
} else {
return e.pageY;
}
};
/**
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
*/
exports.getButton = function(e) {
if (e.type == "dblclick")
return 0;
else if (e.type == "contextmenu")
return 2;
// DOM Event
if (e.preventDefault) {
return e.button;
}
// old IE
else {
return {1:0, 2:2, 4:1}[e.button];
}
};
if (document.documentElement.setCapture) {
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
function onMouseMove(e) {
eventHandler(e);
return exports.stopPropagation(e);
}
var called = false;
function onReleaseCapture(e) {
eventHandler(e);
if (!called) {
called = true;
releaseCaptureHandler();
}
exports.removeListener(el, "mousemove", eventHandler);
exports.removeListener(el, "mouseup", onReleaseCapture);
exports.removeListener(el, "losecapture", onReleaseCapture);
el.releaseCapture();
}
exports.addListener(el, "mousemove", eventHandler);
exports.addListener(el, "mouseup", onReleaseCapture);
exports.addListener(el, "losecapture", onReleaseCapture);
el.setCapture();
};
}
else {
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
function onMouseMove(e) {
eventHandler(e);
e.stopPropagation();
}
function onMouseUp(e) {
eventHandler && eventHandler(e);
releaseCaptureHandler && releaseCaptureHandler();
document.removeEventListener("mousemove", onMouseMove, true);
document.removeEventListener("mouseup", onMouseUp, true);
e.stopPropagation();
}
document.addEventListener("mousemove", onMouseMove, true);
document.addEventListener("mouseup", onMouseUp, true);
};
}
exports.addMouseWheelListener = function(el, callback) {
var max = 0;
var listener = function(e) {
if (e.wheelDelta !== undefined) {
// some versions of Safari (e.g. 5.0.5) report insanely high
// scroll values. These browsers require a higher factor
if (Math.abs(e.wheelDeltaY) > max)
max = Math.abs(e.wheelDeltaY)
if (max > 5000)
factor = 400;
else
factor = 8;
if (e.wheelDeltaX !== undefined) {
e.wheelX = -e.wheelDeltaX / factor;
e.wheelY = -e.wheelDeltaY / factor;
} else {
e.wheelX = 0;
e.wheelY = -e.wheelDelta / factor;
}
}
else {
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
e.wheelX = (e.detail || 0) * 5;
e.wheelY = 0;
} else {
e.wheelX = 0;
e.wheelY = (e.detail || 0) * 5;
}
}
callback(e);
};
exports.addListener(el, "DOMMouseScroll", listener);
exports.addListener(el, "mousewheel", listener);
};
exports.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
var clicks = 0;
var startX, startY;
var listener = function(e) {
clicks += 1;
if (clicks == 1) {
startX = e.clientX;
startY = e.clientY;
setTimeout(function() {
clicks = 0;
}, timeout || 600);
}
var isButton = exports.getButton(e) == button;
if (!isButton || Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
clicks = 0;
if (clicks == count) {
clicks = 0;
callback(e);
}
if (isButton)
return exports.preventDefault(e);
};
exports.addListener(el, "mousedown", listener);
useragent.isIE && exports.addListener(el, "dblclick", listener);
};
function normalizeCommandKeys(callback, e, keyCode) {
var hashId = 0;
if (useragent.isOpera && useragent.isMac) {
hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0)
| (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
} else {
hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0)
| (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
}
if (keyCode in keys.MODIFIER_KEYS) {
switch (keys.MODIFIER_KEYS[keyCode]) {
case "Alt":
hashId = 2;
break;
case "Shift":
hashId = 4;
break
case "Ctrl":
hashId = 1;
break;
default:
hashId = 8;
break;
}
keyCode = 0;
}
if (hashId & 8 && (keyCode == 91 || keyCode == 93)) {
keyCode = 0;
}
// If there is no hashID and the keyCode is not a function key, then
// we don't call the callback as we don't handle a command key here
// (it's a normal key/character input).
if (hashId == 0 && !(keyCode in keys.FUNCTION_KEYS)) {
return false;
}
return callback(e, hashId, keyCode);
}
exports.addCommandKeyListener = function(el, callback) {
var addListener = exports.addListener;
if (useragent.isOldGecko) {
// Old versions of Gecko aka. Firefox < 4.0 didn't repeat the keydown
// event if the user pressed the key for a longer time. Instead, the
// keydown event was fired once and later on only the keypress event.
// To emulate the 'right' keydown behavior, the keyCode of the initial
// keyDown event is stored and in the following keypress events the
// stores keyCode is used to emulate a keyDown event.
var lastKeyDownKeyCode = null;
addListener(el, "keydown", function(e) {
lastKeyDownKeyCode = e.keyCode;
});
addListener(el, "keypress", function(e) {
return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
});
} else {
var lastDown = null;
addListener(el, "keydown", function(e) {
lastDown = e.keyIdentifier || e.keyCode;
return normalizeCommandKeys(callback, e, e.keyCode);
});
// repeated keys are fired as keypress and not keydown events
if (useragent.isMac && useragent.isOpera) {
addListener(el, "keypress", function(e) {
var keyId = e.keyIdentifier || e.keyCode;
if (lastDown !== keyId) {
return normalizeCommandKeys(callback, e, e.keyCode);
} else {
lastDown = null;
}
});
}
}
};
});

View file

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org>
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
*
* Alternatively, the contents of this file may be used under the terms of
@ -38,60 +39,54 @@
define(function(require, exports, module) {
var types = require('pilot/types')
var SelectionType = require('pilot/types/basic').SelectionType
var EventEmitter = {};
var env
EventEmitter._emit =
EventEmitter._dispatchEvent = function(eventName, e) {
this._eventRegistry = this._eventRegistry || {};
var settingTypes = {
selectionStyle: new SelectionType({
data: [ 'line', 'text' ]
})
}
var listeners = this._eventRegistry[eventName];
if (!listeners || !listeners.length) return;
var settings = {
printMargin: {
description: 'Position of the print margin column.',
type: 'number',
defaultValue: 80,
onChange: function onChange(event) {
if (env.editor) env.editor.setPrintMarginColumn(event.value)
}
},
showIvisibles: {
description: 'Whether or not to show invisible characters.',
type: 'bool',
defaultValue: false,
onChange: function onChange(event) {
if (env.editor) env.editor.setShowInvisibles(event.value)
}
},
highlightActiveLine: {
description: 'Whether or not highlight active line.',
type: 'bool',
defaultValue: true,
onChange: function onChange(event) {
if (env.editor) env.editor.setHighlightActiveLine(event.value)
}
},
selectionStyle: {
description: 'Type of text selection.',
type: 'selectionStyle',
defaultValue: 'line',
onChange: function onChange(event) {
if (env.editor) env.editor.setSelectionStyle(event.value)
}
var e = e || {};
e.type = eventName;
for (var i=0; i<listeners.length; i++) {
listeners[i](e);
}
};
EventEmitter.on =
EventEmitter.addEventListener = function(eventName, callback) {
this._eventRegistry = this._eventRegistry || {};
var listeners = this._eventRegistry[eventName];
if (!listeners) {
var listeners = this._eventRegistry[eventName] = [];
}
if (listeners.indexOf(callback) == -1) {
listeners.push(callback);
}
};
EventEmitter.removeListener =
EventEmitter.removeEventListener = function(eventName, callback) {
this._eventRegistry = this._eventRegistry || {};
var listeners = this._eventRegistry[eventName];
if (!listeners) {
return;
}
var index = listeners.indexOf(callback);
if (index !== -1) {
listeners.splice(index, 1);
}
};
EventEmitter.removeAllListeners = function(eventName) {
if (this._eventRegistry) this._eventRegistry[eventName] = [];
}
exports.startup = function startup(data, reason) {
env = data.env
types.registerTypes(settingTypes)
data.env.settings.addSettings(settings)
}
exports.EventEmitter = EventEmitter;
exports.shutdown = function shutdown(data, reason) {
data.env.settings.removeSettings(settings)
}
})
});

840
ace/lib/fixoldbrowsers.js Normal file
View file

@ -0,0 +1,840 @@
// vim:set ts=4 sts=4 sw=4 st:
// -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
// -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
// -- dantman Daniel Friesen Copyright(C) 2010 XXX No License Specified
// -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
// -- Irakli Gozalishvili Copyright (C) 2010 MIT License
/*!
Copyright (c) 2009, 280 North Inc. http://280north.com/
MIT License. http://github.com/280north/narwhal/blob/master/README.md
*/
define(function(require, exports, module) {
require("ace/lib/regexp");
/**
* Brings an environment as close to ECMAScript 5 compliance
* as is possible with the facilities of erstwhile engines.
*
* ES5 Draft
* http://www.ecma-international.org/publications/files/drafts/tc39-2009-050.pdf
*
* NOTE: this is a draft, and as such, the URL is subject to change. If the
* link is broken, check in the parent directory for the latest TC39 PDF.
* http://www.ecma-international.org/publications/files/drafts/
*
* Previous ES5 Draft
* http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
* This is a broken link to the previous draft of ES5 on which most of the
* numbered specification references and quotes herein were taken. Updating
* these references and quotes to reflect the new document would be a welcome
* volunteer project.
*
* @module
*/
/*whatsupdoc*/
//
// Function
// ========
//
// ES-5 15.3.4.5
// http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
if (!Function.prototype.bind) {
var slice = Array.prototype.slice;
Function.prototype.bind = function bind(that) { // .length is 1
// 1. Let Target be the this value.
var target = this;
// 2. If IsCallable(Target) is false, throw a TypeError exception.
// XXX this gets pretty close, for all intents and purposes, letting
// some duck-types slide
if (typeof target.apply !== "function" || typeof target.call !== "function")
return new TypeError();
// 3. Let A be a new (possibly empty) internal list of all of the
// argument values provided after thisArg (arg1, arg2 etc), in order.
var args = slice.call(arguments);
// 4. Let F be a new native ECMAScript object.
// 9. Set the [[Prototype]] internal property of F to the standard
// built-in Function prototype object as specified in 15.3.3.1.
// 10. Set the [[Call]] internal property of F as described in
// 15.3.4.5.1.
// 11. Set the [[Construct]] internal property of F as described in
// 15.3.4.5.2.
// 12. Set the [[HasInstance]] internal property of F as described in
// 15.3.4.5.3.
// 13. The [[Scope]] internal property of F is unused and need not
// exist.
var bound = function bound() {
if (this instanceof bound) {
// 15.3.4.5.2 [[Construct]]
// When the [[Construct]] internal method of a function object,
// F that was created using the bind function is called with a
// list of arguments ExtraArgs the following steps are taken:
// 1. Let target be the value of F's [[TargetFunction]]
// internal property.
// 2. If target has no [[Construct]] internal method, a
// TypeError exception is thrown.
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
// property.
// 4. Let args be a new list containing the same values as the
// list boundArgs in the same order followed by the same
// values as the list ExtraArgs in the same order.
var self = Object.create(target.prototype);
target.apply(self, args.concat(slice.call(arguments)));
return self;
} else {
// 15.3.4.5.1 [[Call]]
// When the [[Call]] internal method of a function object, F,
// which was created using the bind function is called with a
// this value and a list of arguments ExtraArgs the following
// steps are taken:
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
// property.
// 2. Let boundThis be the value of F's [[BoundThis]] internal
// property.
// 3. Let target be the value of F's [[TargetFunction]] internal
// property.
// 4. Let args be a new list containing the same values as the list
// boundArgs in the same order followed by the same values as
// the list ExtraArgs in the same order. 5. Return the
// result of calling the [[Call]] internal method of target
// providing boundThis as the this value and providing args
// as the arguments.
// equiv: target.call(this, ...boundArgs, ...args)
return target.call.apply(
target,
args.concat(slice.call(arguments))
);
}
};
bound.length = (
// 14. If the [[Class]] internal property of Target is "Function", then
typeof target === "function" ?
// a. Let L be the length property of Target minus the length of A.
// b. Set the length own property of F to either 0 or L, whichever is larger.
Math.max(target.length - args.length, 0) :
// 15. Else set the length own property of F to 0.
0
)
// 16. The length own property of F is given attributes as specified in
// 15.3.5.1.
// TODO
// 17. Set the [[Extensible]] internal property of F to true.
// TODO
// 18. Call the [[DefineOwnProperty]] internal method of F with
// arguments "caller", PropertyDescriptor {[[Value]]: null,
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
// false}, and false.
// TODO
// 19. Call the [[DefineOwnProperty]] internal method of F with
// arguments "arguments", PropertyDescriptor {[[Value]]: null,
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
// false}, and false.
// TODO
// NOTE Function objects created using Function.prototype.bind do not
// have a prototype property.
// XXX can't delete it in pure-js.
return bound;
};
}
// Shortcut to an often accessed properties, in order to avoid multiple
// dereference that costs universally.
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
// us it in defining shortcuts.
var call = Function.prototype.call;
var prototypeOfArray = Array.prototype;
var prototypeOfObject = Object.prototype;
var owns = call.bind(prototypeOfObject.hasOwnProperty);
var defineGetter, defineSetter, lookupGetter, lookupSetter, supportsAccessors;
// If JS engine supports accessors creating shortcuts.
if ((supportsAccessors = owns(prototypeOfObject, '__defineGetter__'))) {
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
}
//
// Array
// =====
//
// ES5 15.4.3.2
if (!Array.isArray) {
Array.isArray = function isArray(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};
}
// ES5 15.4.4.18
if (!Array.prototype.forEach) {
Array.prototype.forEach = function forEach(block, thisObject) {
var len = +this.length;
for (var i = 0; i < len; i++) {
if (i in this) {
block.call(thisObject, this[i], i, this);
}
}
};
}
// ES5 15.4.4.19
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
if (!Array.prototype.map) {
Array.prototype.map = function map(fun /*, thisp*/) {
var len = +this.length;
if (typeof fun !== "function")
throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this)
res[i] = fun.call(thisp, this[i], i, this);
}
return res;
};
}
// ES5 15.4.4.20
if (!Array.prototype.filter) {
Array.prototype.filter = function filter(block /*, thisp */) {
var values = [];
var thisp = arguments[1];
for (var i = 0; i < this.length; i++)
if (block.call(thisp, this[i]))
values.push(this[i]);
return values;
};
}
// ES5 15.4.4.16
if (!Array.prototype.every) {
Array.prototype.every = function every(block /*, thisp */) {
var thisp = arguments[1];
for (var i = 0; i < this.length; i++)
if (!block.call(thisp, this[i]))
return false;
return true;
};
}
// ES5 15.4.4.17
if (!Array.prototype.some) {
Array.prototype.some = function some(block /*, thisp */) {
var thisp = arguments[1];
for (var i = 0; i < this.length; i++)
if (block.call(thisp, this[i]))
return true;
return false;
};
}
// ES5 15.4.4.21
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
if (!Array.prototype.reduce) {
Array.prototype.reduce = function reduce(fun /*, initial*/) {
var len = +this.length;
if (typeof fun !== "function")
throw new TypeError();
// no value to return if no initial value and an empty array
if (len === 0 && arguments.length === 1)
throw new TypeError();
var i = 0;
if (arguments.length >= 2) {
var rv = arguments[1];
} else {
do {
if (i in this) {
rv = this[i++];
break;
}
// if array contains no values, no initial value to return
if (++i >= len)
throw new TypeError();
} while (true);
}
for (; i < len; i++) {
if (i in this)
rv = fun.call(null, rv, this[i], i, this);
}
return rv;
};
}
// ES5 15.4.4.22
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
if (!Array.prototype.reduceRight) {
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
var len = +this.length;
if (typeof fun !== "function")
throw new TypeError();
// no value to return if no initial value, empty array
if (len === 0 && arguments.length === 1)
throw new TypeError();
var i = len - 1;
if (arguments.length >= 2) {
var rv = arguments[1];
} else {
do {
if (i in this) {
rv = this[i--];
break;
}
// if array contains no values, no initial value to return
if (--i < 0)
throw new TypeError();
} while (true);
}
for (; i >= 0; i--) {
if (i in this)
rv = fun.call(null, rv, this[i], i, this);
}
return rv;
};
}
// ES5 15.4.4.14
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function indexOf(value /*, fromIndex */ ) {
var length = this.length;
if (!length)
return -1;
var i = arguments[1] || 0;
if (i >= length)
return -1;
if (i < 0)
i += length;
for (; i < length; i++) {
if (!owns(this, i))
continue;
if (value === this[i])
return i;
}
return -1;
};
}
// ES5 15.4.4.15
if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function lastIndexOf(value /*, fromIndex */) {
var length = this.length;
if (!length)
return -1;
var i = arguments[1] || length;
if (i < 0)
i += length;
i = Math.min(i, length - 1);
for (; i >= 0; i--) {
if (!owns(this, i))
continue;
if (value === this[i])
return i;
}
return -1;
};
}
//
// Object
// ======
//
// ES5 15.2.3.2
if (!Object.getPrototypeOf) {
// https://github.com/kriskowal/es5-shim/issues#issue/2
// http://ejohn.org/blog/objectgetprototypeof/
// recommended by fschaefer on github
Object.getPrototypeOf = function getPrototypeOf(object) {
return object.__proto__ || object.constructor.prototype;
// or undefined if not available in this engine
};
}
// ES5 15.2.3.3
if (!Object.getOwnPropertyDescriptor) {
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
"non-object: ";
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
if ((typeof object !== "object" && typeof object !== "function") || object === null)
throw new TypeError(ERR_NON_OBJECT + object);
// If object does not owns property return undefined immediately.
if (!owns(object, property))
return undefined;
var despriptor, getter, setter;
// If object has a property then it's for sure both `enumerable` and
// `configurable`.
despriptor = { enumerable: true, configurable: true };
// If JS engine supports accessor properties then property may be a
// getter or setter.
if (supportsAccessors) {
// Unfortunately `__lookupGetter__` will return a getter even
// if object has own non getter property along with a same named
// inherited getter. To avoid misbehavior we temporary remove
// `__proto__` so that `__lookupGetter__` will return getter only
// if it's owned by an object.
var prototype = object.__proto__;
object.__proto__ = prototypeOfObject;
var getter = lookupGetter(object, property);
var setter = lookupSetter(object, property);
// Once we have getter and setter we can put values back.
object.__proto__ = prototype;
if (getter || setter) {
if (getter) descriptor.get = getter;
if (setter) descriptor.set = setter;
// If it was accessor property we're done and return here
// in order to avoid adding `value` to the descriptor.
return descriptor;
}
}
// If we got this far we know that object has an own property that is
// not an accessor so we set it as a value and return descriptor.
descriptor.value = object[property];
return descriptor;
};
}
// ES5 15.2.3.4
if (!Object.getOwnPropertyNames) {
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
return Object.keys(object);
};
}
// ES5 15.2.3.5
if (!Object.create) {
Object.create = function create(prototype, properties) {
var object;
if (prototype === null) {
object = { "__proto__": null };
} else {
if (typeof prototype !== "object")
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
var Type = function () {};
Type.prototype = prototype;
object = new Type();
// IE has no built-in implementation of `Object.getPrototypeOf`
// neither `__proto__`, but this manually setting `__proto__` will
// guarantee that `Object.getPrototypeOf` will work as expected with
// objects created using `Object.create`
object.__proto__ = prototype;
}
if (typeof properties !== "undefined")
Object.defineProperties(object, properties);
return object;
};
}
// ES5 15.2.3.6
if (!Object.defineProperty) {
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
"on this javascript engine";
Object.defineProperty = function defineProperty(object, property, descriptor) {
if (typeof object !== "object" && typeof object !== "function")
throw new TypeError(ERR_NON_OBJECT_TARGET + object);
if (typeof object !== "object" || object === null)
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
// If it's a data property.
if (owns(descriptor, "value")) {
// fail silently if "writable", "enumerable", or "configurable"
// are requested but not supported
/*
// alternate approach:
if ( // can't implement these features; allow false but not true
!(owns(descriptor, "writable") ? descriptor.writable : true) ||
!(owns(descriptor, "enumerable") ? descriptor.enumerable : true) ||
!(owns(descriptor, "configurable") ? descriptor.configurable : true)
)
throw new RangeError(
"This implementation of Object.defineProperty does not " +
"support configurable, enumerable, or writable."
);
*/
if (supportsAccessors && (lookupGetter(object, property) ||
lookupSetter(object, property)))
{
// As accessors are supported only on engines implementing
// `__proto__` we can safely override `__proto__` while defining
// a property to make sure that we don't hit an inherited
// accessor.
var prototype = object.__proto__;
object.__proto__ = prototypeOfObject;
// Deleting a property anyway since getter / setter may be
// defined on object itself.
delete object[property];
object[property] = descriptor.value;
// Setting original `__proto__` back now.
object.prototype;
} else {
object[property] = descriptor.value;
}
} else {
if (!supportsAccessors)
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
// If we got that far then getters and setters can be defined !!
if (owns(descriptor, "get"))
defineGetter(object, property, descriptor.get);
if (owns(descriptor, "set"))
defineSetter(object, property, descriptor.set);
}
return object;
};
}
// ES5 15.2.3.7
if (!Object.defineProperties) {
Object.defineProperties = function defineProperties(object, properties) {
for (var property in properties) {
if (owns(properties, property))
Object.defineProperty(object, property, properties[property]);
}
return object;
};
}
// ES5 15.2.3.8
if (!Object.seal) {
Object.seal = function seal(object) {
// this is misleading and breaks feature-detection, but
// allows "securable" code to "gracefully" degrade to working
// but insecure code.
return object;
};
}
// ES5 15.2.3.9
if (!Object.freeze) {
Object.freeze = function freeze(object) {
// this is misleading and breaks feature-detection, but
// allows "securable" code to "gracefully" degrade to working
// but insecure code.
return object;
};
}
// detect a Rhino bug and patch it
try {
Object.freeze(function () {});
} catch (exception) {
Object.freeze = (function freeze(freezeObject) {
return function freeze(object) {
if (typeof object === "function") {
return object;
} else {
return freezeObject(object);
}
};
})(Object.freeze);
}
// ES5 15.2.3.10
if (!Object.preventExtensions) {
Object.preventExtensions = function preventExtensions(object) {
// this is misleading and breaks feature-detection, but
// allows "securable" code to "gracefully" degrade to working
// but insecure code.
return object;
};
}
// ES5 15.2.3.11
if (!Object.isSealed) {
Object.isSealed = function isSealed(object) {
return false;
};
}
// ES5 15.2.3.12
if (!Object.isFrozen) {
Object.isFrozen = function isFrozen(object) {
return false;
};
}
// ES5 15.2.3.13
if (!Object.isExtensible) {
Object.isExtensible = function isExtensible(object) {
return true;
};
}
// ES5 15.2.3.14
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
if (!Object.keys) {
var hasDontEnumBug = true,
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
for (var key in {"toString": null})
hasDontEnumBug = false;
Object.keys = function keys(object) {
if (
typeof object !== "object" && typeof object !== "function"
|| object === null
)
throw new TypeError("Object.keys called on a non-object");
var keys = [];
for (var name in object) {
if (owns(object, name)) {
keys.push(name);
}
}
if (hasDontEnumBug) {
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
var dontEnum = dontEnums[i];
if (owns(object, dontEnum)) {
keys.push(dontEnum);
}
}
}
return keys;
};
}
//
// Date
// ====
//
// ES5 15.9.5.43
// Format a Date object as a string according to a subset of the ISO-8601 standard.
// Useful in Atom, among other things.
if (!Date.prototype.toISOString) {
Date.prototype.toISOString = function toISOString() {
return (
this.getUTCFullYear() + "-" +
(this.getUTCMonth() + 1) + "-" +
this.getUTCDate() + "T" +
this.getUTCHours() + ":" +
this.getUTCMinutes() + ":" +
this.getUTCSeconds() + "Z"
);
}
}
// ES5 15.9.4.4
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
// ES5 15.9.5.44
if (!Date.prototype.toJSON) {
Date.prototype.toJSON = function toJSON(key) {
// This function provides a String representation of a Date object for
// use by JSON.stringify (15.12.3). When the toJSON method is called
// with argument key, the following steps are taken:
// 1. Let O be the result of calling ToObject, giving it the this
// value as its argument.
// 2. Let tv be ToPrimitive(O, hint Number).
// 3. If tv is a Number and is not finite, return null.
// XXX
// 4. Let toISO be the result of calling the [[Get]] internal method of
// O with argument "toISOString".
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
if (typeof this.toISOString !== "function")
throw new TypeError();
// 6. Return the result of calling the [[Call]] internal method of
// toISO with O as the this value and an empty argument list.
return this.toISOString();
// NOTE 1 The argument is ignored.
// NOTE 2 The toJSON function is intentionally generic; it does not
// require that its this value be a Date object. Therefore, it can be
// transferred to other kinds of objects for use as a method. However,
// it does require that any such object have a toISOString method. An
// object is free to use the argument key to filter its
// stringification.
};
}
// 15.9.4.2 Date.parse (string)
// 15.9.1.15 Date Time String Format
// Date.parse
// based on work shared by Daniel Friesen (dantman)
// http://gist.github.com/303249
if (isNaN(Date.parse("T00:00"))) {
// XXX global assignment won't work in embeddings that use
// an alternate object for the context.
Date = (function(NativeDate) {
// Date.length === 7
var Date = function(Y, M, D, h, m, s, ms) {
var length = arguments.length;
if (this instanceof NativeDate) {
var date = length === 1 && String(Y) === Y ? // isString(Y)
// We explicitly pass it through parse:
new NativeDate(Date.parse(Y)) :
// We have to manually make calls depending on argument
// length here
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
length >= 5 ? new NativeDate(Y, M, D, h, m) :
length >= 4 ? new NativeDate(Y, M, D, h) :
length >= 3 ? new NativeDate(Y, M, D) :
length >= 2 ? new NativeDate(Y, M) :
length >= 1 ? new NativeDate(Y) :
new NativeDate();
// Prevent mixups with unfixed Date object
date.constructor = Date;
return date;
}
return NativeDate.apply(this, arguments);
};
// 15.9.1.15 Date Time String Format
var isoDateExpression = new RegExp("^" +
"(?:" + // optional year-month-day
"(" + // year capture
"(?:[+-]\\d\\d)?" + // 15.9.1.15.1 Extended years
"\\d\\d\\d\\d" + // four-digit year
")" +
"(?:-" + // optional month-day
"(\\d\\d)" + // month capture
"(?:-" + // optional day
"(\\d\\d)" + // day capture
")?" +
")?" +
")?" +
"(?:T" + // hour:minute:second.subsecond
"(\\d\\d)" + // hour capture
":(\\d\\d)" + // minute capture
"(?::" + // optional :second.subsecond
"(\\d\\d)" + // second capture
"(?:\\.(\\d\\d\\d))?" + // milisecond capture
")?" +
")?" +
"(?:" + // time zone
"Z|" + // UTC capture
"([+-])(\\d\\d):(\\d\\d)" + // timezone offset
// capture sign, hour, minute
")?" +
"$");
// Copy any custom methods a 3rd party library may have added
for (var key in NativeDate)
Date[key] = NativeDate[key];
// Copy "native" methods explicitly; they may be non-enumerable
Date.now = NativeDate.now;
Date.UTC = NativeDate.UTC;
Date.prototype = NativeDate.prototype;
Date.prototype.constructor = Date;
// Upgrade Date.parse to handle the ISO dates we use
// TODO review specification to ascertain whether it is
// necessary to implement partial ISO date strings.
Date.parse = function parse(string) {
var match = isoDateExpression.exec(string);
if (match) {
match.shift(); // kill match[0], the full match
// recognize times without dates before normalizing the
// numeric values, for later use
var timeOnly = match[0] === undefined;
// parse numerics
for (var i = 0; i < 10; i++) {
// skip + or - for the timezone offset
if (i === 7)
continue;
// Note: parseInt would read 0-prefix numbers as
// octal. Number constructor or unary + work better
// here:
match[i] = +(match[i] || (i < 3 ? 1 : 0));
// match[1] is the month. Months are 0-11 in JavaScript
// Date objects, but 1-12 in ISO notation, so we
// decrement.
if (i === 1)
match[i]--;
}
// if no year-month-date is provided, return a milisecond
// quantity instead of a UTC date number value.
if (timeOnly)
return ((match[3] * 60 + match[4]) * 60 + match[5]) * 1000 + match[6];
// account for an explicit time zone offset if provided
var offset = (match[8] * 60 + match[9]) * 60 * 1000;
if (match[6] === "-")
offset = -offset;
return NativeDate.UTC.apply(this, match.slice(0, 7)) + offset;
}
return NativeDate.parse.apply(this, arguments);
};
return Date;
})(Date);
}
//
// String
// ======
//
// ES5 15.5.4.20
if (!String.prototype.trim) {
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
var trimBeginRegexp = /^\s\s*/;
var trimEndRegexp = /\s\s*$/;
String.prototype.trim = function trim() {
return String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
};
}
});

118
ace/lib/keys.js Normal file
View file

@ -0,0 +1,118 @@
/*! @license
==========================================================================
SproutCore -- JavaScript Application Framework
copyright 2006-2009, Sprout Systems Inc., Apple Inc. and contributors.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
SproutCore and the SproutCore logo are trademarks of Sprout Systems, Inc.
For more information about SproutCore, visit http://www.sproutcore.com
==========================================================================
@license */
// Most of the following code is taken from SproutCore with a few changes.
define(function(require, exports, module) {
var oop = require("ace/lib/oop");
/**
* Helper functions and hashes for key handling.
*/
var Keys = (function() {
var ret = {
MODIFIER_KEYS: {
16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
},
KEY_MODS: {
"ctrl": 1, "alt": 2, "option" : 2,
"shift": 4, "meta": 8, "command": 8
},
FUNCTION_KEYS : {
8 : "Backspace",
9 : "Tab",
13 : "Return",
19 : "Pause",
27 : "Esc",
32 : "Space",
33 : "PageUp",
34 : "PageDown",
35 : "End",
36 : "Home",
37 : "Left",
38 : "Up",
39 : "Right",
40 : "Down",
44 : "Print",
45 : "Insert",
46 : "Delete",
112: "F1",
113: "F2",
114: "F3",
115: "F4",
116: "F5",
117: "F6",
118: "F7",
119: "F8",
120: "F9",
121: "F10",
122: "F11",
123: "F12",
144: "Numlock",
145: "Scrolllock"
},
PRINTABLE_KEYS: {
32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
188: ',', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\',
221: ']', 222: '\"'
}
};
// A reverse map of FUNCTION_KEYS
for (i in ret.FUNCTION_KEYS) {
var name = ret.FUNCTION_KEYS[i].toUpperCase();
ret[name] = parseInt(i, 10);
}
// Add the MODIFIER_KEYS, FUNCTION_KEYS and PRINTABLE_KEYS to the KEY
// variables as well.
oop.mixin(ret, ret.MODIFIER_KEYS);
oop.mixin(ret, ret.PRINTABLE_KEYS);
oop.mixin(ret, ret.FUNCTION_KEYS);
return ret;
})();
oop.mixin(exports, Keys);
exports.keyCodeToString = function(keyCode) {
return (Keys[keyCode] || String.fromCharCode(keyCode)).toLowerCase();
}
});

150
ace/lib/lang.js Normal file
View file

@ -0,0 +1,150 @@
/* ***** 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):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* 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) {
exports.stringReverse = function(string) {
return string.split("").reverse().join("");
};
exports.stringRepeat = function (string, count) {
return new Array(count + 1).join(string);
};
var trimBeginRegexp = /^\s\s*/;
var trimEndRegexp = /\s\s*$/;
exports.stringTrimLeft = function (string) {
return string.replace(trimBeginRegexp, '')
};
exports.stringTrimRight = function (string) {
return string.replace(trimEndRegexp, '');
};
exports.copyObject = function(obj) {
var copy = {};
for (var key in obj) {
copy[key] = obj[key];
}
return copy;
};
exports.copyArray = function(array){
var copy = [];
for (i=0, l=array.length; i<l; i++) {
if (array[i] && typeof array[i] == "object")
copy[i] = this.copyObject( array[i] );
else
copy[i] = array[i]
}
return copy;
};
exports.deepCopy = function (obj) {
if (typeof obj != "object") {
return obj;
}
var copy = obj.constructor();
for (var key in obj) {
if (typeof obj[key] == "object") {
copy[key] = this.deepCopy(obj[key]);
} else {
copy[key] = obj[key];
}
}
return copy;
}
exports.arrayToMap = function(arr) {
var map = {};
for (var i=0; i<arr.length; i++) {
map[arr[i]] = 1;
}
return map;
};
/**
* splice out of 'array' anything that === 'value'
*/
exports.arrayRemove = function(array, value) {
for (var i = 0; i <= array.length; i++) {
if (value === array[i]) {
array.splice(i, 1);
}
}
};
exports.escapeRegExp = function(str) {
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
};
exports.deferredCall = function(fcn) {
var timer = null;
var callback = function() {
timer = null;
fcn();
};
var deferred = function(timeout) {
if (!timer) {
timer = setTimeout(callback, timeout || 0);
}
return deferred;
}
deferred.schedule = deferred;
deferred.call = function() {
this.cancel();
fcn();
return deferred;
};
deferred.cancel = function() {
clearTimeout(timer);
timer = null;
return deferred;
};
return deferred;
};
});

View file

@ -1,5 +1,4 @@
/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK *****
/* ***** 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
@ -20,7 +19,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
* Fabian Jakobs <fabian AT ajax DOT org>
*
* 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
@ -38,14 +37,24 @@
define(function(require, exports, module) {
var settings = require("ace/settings/default-settings")
exports.inherits = (function() {
var tempCtor = function() {};
return function(ctor, superCtor) {
tempCtor.prototype = superCtor.prototype;
ctor.super_ = superCtor.prototype;
ctor.prototype = new tempCtor();
ctor.prototype.constructor = ctor;
}
}());
exports.startup = function startup(data, reason) {
settings.startup(data, reason)
}
exports.mixin = function(obj, mixin) {
for (var key in mixin) {
obj[key] = mixin[key];
}
};
exports.shutdown = function shutdown(data, reason) {
settings.shutdown(data, reason)
}
exports.implement = function(proto, mixin) {
exports.mixin(proto, mixin);
};
})
});

107
ace/lib/regexp.js Normal file
View file

@ -0,0 +1,107 @@
define(function(require, exports, module) {
// Based on code from:
//
// XRegExp 1.5.0
// (c) 2007-2010 Steven Levithan
// MIT License
// <http://xregexp.com>
// Provides an augmented, extensible, cross-browser implementation of regular expressions,
// including support for additional syntax, flags, and methods
//---------------------------------
// Private variables
//---------------------------------
var real = {
exec: RegExp.prototype.exec,
test: RegExp.prototype.test,
match: String.prototype.match,
replace: String.prototype.replace,
split: String.prototype.split
},
compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
compliantLastIndexIncrement = function () {
var x = /^/g;
real.test.call(x, "");
return !x.lastIndex;
}();
//---------------------------------
// Overriden native methods
//---------------------------------
// Adds named capture support (with backreferences returned as `result.name`), and fixes two
// cross-browser issues per ES3:
// - Captured values for nonparticipating capturing groups should be returned as `undefined`,
// rather than the empty string.
// - `lastIndex` should not be incremented after zero-length matches.
RegExp.prototype.exec = function (str) {
var match = real.exec.apply(this, arguments),
name, r2;
if (match) {
// Fix browsers whose `exec` methods don't consistently return `undefined` for
// nonparticipating capturing groups
if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
// Using `str.slice(match.index)` rather than `match[0]` in case lookahead allowed
// matching due to characters outside the match
real.replace.call(str.slice(match.index), r2, function () {
for (var i = 1; i < arguments.length - 2; i++) {
if (arguments[i] === undefined)
match[i] = undefined;
}
});
}
// Attach named capture properties
if (this._xregexp && this._xregexp.captureNames) {
for (var i = 1; i < match.length; i++) {
name = this._xregexp.captureNames[i - 1];
if (name)
match[name] = match[i];
}
}
// Fix browsers that increment `lastIndex` after zero-length matches
if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
this.lastIndex--;
}
return match;
};
// Don't override `test` if it won't change anything
if (!compliantLastIndexIncrement) {
// Fix browser bug in native method
RegExp.prototype.test = function (str) {
// Use the native `exec` to skip some processing overhead, even though the overriden
// `exec` would take care of the `lastIndex` fix
var match = real.exec.call(this, str);
// Fix browsers that increment `lastIndex` after zero-length matches
if (match && this.global && !match[0].length && (this.lastIndex > match.index))
this.lastIndex--;
return !!match;
};
}
//---------------------------------
// Private helper functions
//---------------------------------
function getNativeFlags (regex) {
return (regex.global ? "g" : "") +
(regex.ignoreCase ? "i" : "") +
(regex.multiline ? "m" : "") +
(regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
(regex.sticky ? "y" : "");
};
function indexOf (array, item, from) {
if (Array.prototype.indexOf) // Use the native array method if available
return array.indexOf(item, from);
for (var i = from || 0; i < array.length; i++) {
if (array[i] === item)
return i;
}
return -1;
};
});

99
ace/lib/useragent.js Normal file
View file

@ -0,0 +1,99 @@
/* ***** 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):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
var ua = navigator.userAgent;
var av = navigator.appVersion;
/** Is the user using a browser that identifies itself as Windows */
exports.isWin = (os == "win");
/** Is the user using a browser that identifies itself as Mac OS */
exports.isMac = (os == "mac");
/** Is the user using a browser that identifies itself as Linux */
exports.isLinux = (os == "linux");
exports.isIE = ! + "\v1";
/** Is this Firefox or related? */
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
/** oldGecko == rev < 2.0 **/
exports.isOldGecko = exports.isGecko && /rv\:1/.test(navigator.userAgent);
/** Is this Opera */
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
/** Is the user using a browser that identifies itself as WebKit */
exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
exports.isIPad = ua.indexOf("iPad") >= 0;
/**
* I hate doing this, but we need some way to determine if the user is on a Mac
* The reason is that users have different expectations of their key combinations.
*
* Take copy as an example, Mac people expect to use CMD or APPLE + C
* Windows folks expect to use CTRL + C
*/
exports.OS = {
LINUX: 'LINUX',
MAC: 'MAC',
WINDOWS: 'WINDOWS'
};
/**
* Return an exports.OS constant
*/
exports.getOS = function() {
if (exports.isMac) {
return exports.OS['MAC'];
} else if (exports.isLinux) {
return exports.OS['LINUX'];
} else {
return exports.OS['WINDOWS'];
}
};
});

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var Behaviour = require('ace/mode/behaviour').Behaviour;
var CstyleBehaviour = function () {

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var Behaviour = require('ace/mode/behaviour').Behaviour;
var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour;

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var c_cppHighlightRules = require("ace/mode/c_cpp_highlight_rules").c_cppHighlightRules;

View file

@ -40,8 +40,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -39,7 +39,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var ClojureHighlightRules = require("ace/mode/clojure_highlight_rules").ClojureHighlightRules;

View file

@ -39,8 +39,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -43,7 +43,7 @@ var Outdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
var Range = require("ace/range").Range;
var TextMode = require("ace/mode/text").Mode;
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
function Mode() {
this.$tokenizer = new Tokenizer(new Rules().getRules());
@ -98,7 +98,7 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) {
var doc = session.getDocument();
var worker = new WorkerClient(["ace", "pilot"], "worker-coffee.js", "ace/mode/coffee_worker", "Worker");
var worker = new WorkerClient(["ace"], "worker-coffee.js", "ace/mode/coffee_worker", "Worker");
worker.call("setValue", [doc.getValue()]);
doc.on("change", function(e) {

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../../support/paths");
require("../../../support/paths");
}
define(function(require, exports, module) {

View file

@ -37,8 +37,10 @@
define(function(require, exports, module) {
require("pilot/oop").inherits(CoffeeHighlightRules,
require("ace/mode/text_highlight_rules").TextHighlightRules);
require("ace/lib/oop").inherits(
CoffeeHighlightRules,
require("ace/mode/text_highlight_rules").TextHighlightRules
);
function CoffeeHighlightRules() {
var identifier = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var Mirror = require("ace/worker/mirror").Mirror;
var coffee = require("ace/mode/coffee/coffee-script");

View file

@ -1,6 +1,6 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var CSharpHighlightRules = require("ace/mode/csharp_highlight_rules").CSharpHighlightRules;

View file

@ -1,7 +1,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
@ -79,7 +79,7 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) {
var doc = session.getDocument();
var worker = new WorkerClient(["ace", "pilot"], "worker-css.js", "ace/mode/css_worker", "Worker");
var worker = new WorkerClient(["ace"], "worker-css.js", "ace/mode/css_worker", "Worker");
worker.call("setValue", [doc.getValue()]);
doc.on("change", function(e) {

View file

@ -37,8 +37,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var CssHighlightRules = function() {

View file

@ -36,12 +36,12 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var CssMode = require("ace/mode/css").Mode;
var assert = require("ace/test/assertions");
@ -54,7 +54,7 @@ module.exports = {
},
"test: toggle comment lines should not do anything" : function() {
var session = new EditSession([" abc", "cde", "fg"].join("\n"));
var session = new Buffer([" abc", "cde", "fg"].join("\n"));
var comment = this.mode.toggleCommentLines("start", session, 0, 1);
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var Mirror = require("ace/worker/mirror").Mirror;
var CSSLint = require("ace/mode/css/csslint").CSSLint;

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var DocCommentHighlightRules = function() {

View file

@ -1,6 +1,6 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var JavaScriptMode = require("ace/mode/javascript").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var GroovyHighlightRules = require("ace/mode/groovy_highlight_rules").GroovyHighlightRules;

View file

@ -1,7 +1,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var CssMode = require("ace/mode/css").Mode;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
@ -195,4 +195,4 @@ var HtmlHighlightRules = function() {
oop.inherits(HtmlHighlightRules, TextHighlightRules);
exports.HtmlHighlightRules = HtmlHighlightRules;
});
});

View file

@ -36,12 +36,12 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var Range = require("ace/range").Range;
var HtmlMode = require("ace/mode/html").Mode;
var assert = require("ace/test/assertions");
@ -52,7 +52,7 @@ module.exports = {
},
"test: toggle comment lines should not do anything" : function() {
var session = new EditSession([" abc", "cde", "fg"]);
var session = new Buffer([" abc", "cde", "fg"]);
var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", session, 0, 1);

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -1,6 +1,6 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var JavaScriptMode = require("ace/mode/javascript").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var JavaHighlightRules = require("ace/mode/java_highlight_rules").JavaHighlightRules;

View file

@ -1,7 +1,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
@ -126,7 +126,7 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) {
var doc = session.getDocument();
var worker = new WorkerClient(["ace", "pilot"], "worker-javascript.js", "ace/mode/javascript_worker", "JavaScriptWorker");
var worker = new WorkerClient(["ace"], "worker-javascript.js", "ace/mode/javascript_worker", "JavaScriptWorker");
worker.call("setValue", [doc.getValue()]);
doc.on("change", function(e) {

View file

@ -49,7 +49,7 @@
define(function(require, exports, module) {
var definitions = require("ace/narcissus/jsdefs");
var definitions = require("ace/mode/javascript/jsdefs");
// Set constants in the local scope.
eval(definitions.consts);

View file

@ -51,8 +51,8 @@
define(function(require, exports, module) {
var lexer = require("ace/narcissus/jslex");
var definitions = require("ace/narcissus/jsdefs");
var lexer = require("ace/mode/javascript/jslex");
var definitions = require("ace/mode/javascript/jsdefs");
const StringMap = definitions.StringMap;
const Stack = definitions.Stack;

View file

@ -38,8 +38,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var unicode = require("ace/unicode");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -36,12 +36,12 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {
var EditSession = require("ace/edit_session").EditSession;
var Buffer = require("ace/model/buffer").Buffer;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var assert = require("ace/test/assertions");
@ -61,21 +61,21 @@ module.exports = {
},
"test: toggle comment lines should prepend '//' to each line" : function() {
var session = new EditSession([" abc", "cde", "fg"]);
var session = new Buffer([" abc", "cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", session, 0, 1);
assert.equal(["// abc", "//cde", "fg"].join("\n"), session.toString());
},
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
var session = new EditSession(["// abc", "//cde", "fg"]);
var session = new Buffer(["// abc", "//cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", session, 0, 1);
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
},
"test: toggle comment lines twice should return the original text" : function() {
var session = new EditSession([" abc", "cde", "fg"]);
var session = new Buffer([" abc", "cde", "fg"]);
this.mode.toggleCommentLines("start", session, 0, 2);
this.mode.toggleCommentLines("start", session, 0, 2);
@ -83,14 +83,14 @@ module.exports = {
},
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
var session = new EditSession(["// abc", "//cde", "fg"]);
var session = new Buffer(["// abc", "//cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", session, 0, 2);
assert.equal(["//// abc", "////cde", "//fg"].join("\n"), session.toString());
},
"test: toggle comment on a comment line with leading white space": function() {
var session = new EditSession(["//cde", " //fg"]);
var session = new Buffer(["//cde", " //fg"]);
var comment = this.mode.toggleCommentLines("start", session, 0, 1);
assert.equal(["cde", " fg"].join("\n"), session.toString());
@ -140,13 +140,13 @@ module.exports = {
},
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
var session = new EditSession([" function foo() {", " bla", " }"]);
var session = new Buffer([" function foo() {", " bla", " }"]);
this.mode.autoOutdent("start", session, 2);
assert.equal(" }", session.getLine(2));
},
"test: no auto outdent if no matching brace is found" : function() {
var session = new EditSession([" function foo()", " bla", " }"]);
var session = new Buffer([" function foo()", " bla", " }"]);
this.mode.autoOutdent("start", session, 2);
assert.equal(" }", session.getLine(2));
}

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -1,9 +1,9 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var Mirror = require("ace/worker/mirror").Mirror;
//var lint = require("ace/worker/jslint").JSLINT;
var lint = require("ace/worker/jshint").JSHINT;
var lint = require("ace/mode/javascript/jshint").JSHINT;
var Parser = require("ace/mode/javascript/jsparse");
var JavaScriptWorker = exports.JavaScriptWorker = function(sender) {
Mirror.call(this, sender);
@ -18,13 +18,9 @@ oop.inherits(JavaScriptWorker, Mirror);
var value = this.doc.getValue();
value = value.replace(/^#!.*\n/, "\n");
// var start = new Date();
var parser = require("ace/narcissus/jsparse");
try {
parser.parse(value);
Parser.parse(value);
} catch(e) {
// console.log("narcissus")
// console.log(e);
this.sender.emit("narcissus", {
row: e.lineno-1,
column: null, // TODO convert e.cursor
@ -32,15 +28,10 @@ oop.inherits(JavaScriptWorker, Mirror);
type: "error"
});
return;
} finally {
// console.log("parse time: " + (new Date() - start));
}
// var start = new Date();
// console.log("jslint")
lint(value, {undef: false, onevar: false, passfail: false});
this.sender.emit("jslint", lint.errors);
// console.log("lint time: " + (new Date() - start));
}
}).call(JavaScriptWorker.prototype);

View file

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var HighlightRules = require("ace/mode/json_highlight_rules").JsonHighlightRules;

View file

@ -38,8 +38,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var JsonHighlightRules = function() {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var OcamlHighlightRules = require("ace/mode/ocaml_highlight_rules").OcamlHighlightRules;

View file

@ -39,8 +39,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var OcamlHighlightRules = function() {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var PerlHighlightRules = require("ace/mode/perl_highlight_rules").PerlHighlightRules;

View file

@ -37,8 +37,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var PerlHighlightRules = function() {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var PhpHighlightRules = require("ace/mode/php_highlight_rules").PhpHighlightRules;

View file

@ -38,8 +38,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var PythonHighlightRules = require("ace/mode/python_highlight_rules").PythonHighlightRules;

View file

@ -41,8 +41,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var PythonHighlightRules = function() {

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var RubyHighlightRules = require("ace/mode/ruby_highlight_rules").RubyHighlightRules;

View file

@ -38,8 +38,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var RubyHighlightRules = function() {

View file

@ -37,7 +37,7 @@
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("../../../support/paths");
require("../../support/paths");
}
define(function(require, exports, module) {

View file

@ -1,6 +1,6 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var JavaScriptMode = require("ace/mode/javascript").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var ScalaHighlightRules = require("ace/mode/scala_highlight_rules").ScalaHighlightRules;

View file

@ -1,7 +1,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var ScssHighlightRules = require("ace/mode/scss_highlight_rules").ScssHighlightRules;

View file

@ -37,8 +37,8 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var oop = require("ace/lib/oop");
var lang = require("ace/lib/lang");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var ScssHighlightRules = function() {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var XmlMode = require("ace/mode/text").Mode;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var oop = require("ace/lib/oop");
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules;

View file

@ -97,21 +97,21 @@ var Mode = function() {
return null;
};
this.highlightSelection = function(editor) {
var session = editor.session;
if (!session.$selectionOccurrences)
session.$selectionOccurrences = [];
this.highlightSelection = function(windowModel) {
var buffer = windowModel.buffer;
if (!buffer._selectionOccurrences)
buffer._selectionOccurrences = [];
if (session.$selectionOccurrences.length)
this.clearSelectionHighlight(editor);
if (buffer._selectionOccurrences.length)
this.clearSelectionHighlight(windowModel);
var selection = editor.getSelectionRange();
var selection = windowModel.selection.getRange();
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 line = buffer.getLine(selection.start.row);
var lineCols = line.length;
var needle = line.substring(Math.max(startOuter, 0),
Math.min(endOuter, lineCols));
@ -125,7 +125,7 @@ var Mode = function() {
if (!/^[\w\d]+$/.test(needle))
return;
var cursor = editor.getCursorPosition();
var cursor = windowModel.selection.getCursor();
var newOptions = {
wrap: true,
@ -134,29 +134,32 @@ var Mode = function() {
needle: needle
};
var currentOptions = editor.$search.getOptions();
editor.$search.set(newOptions);
var search = windowModel.search;
var currentOptions = search.getOptions();
search.set(newOptions);
var ranges = editor.$search.findAll(session);
var ranges = search.findAll(buffer);
ranges.forEach(function(range) {
if (!range.contains(cursor.row, cursor.column)) {
var marker = session.addMarker(range, "ace_selected_word", "text");
session.$selectionOccurrences.push(marker);
var marker = buffer.addMarker(range, "ace_selected_word", "text");
buffer._selectionOccurrences.push(marker);
}
});
editor.$search.set(currentOptions);
search.set(currentOptions);
};
this.clearSelectionHighlight = function(editor) {
if (!editor.session.$selectionOccurrences)
this.clearSelectionHighlight = function(windowModel) {
var buffer = windowModel.buffer;
if (!buffer._selectionOccurrences)
return;
editor.session.$selectionOccurrences.forEach(function(marker) {
editor.session.removeMarker(marker);
buffer._selectionOccurrences.forEach(function(marker) {
buffer.removeMarker(marker);
});
editor.session.$selectionOccurrences = [];
buffer._selectionOccurrences = [];
};
this.createModeDelegates = function (mapping) {

View file

@ -37,7 +37,7 @@
define(function(require, exports, module) {
var lang = require("pilot/lang");
var lang = require("ace/lib/lang");
var TextHighlightRules = function() {

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