Merge pull request #1449 from ajaxorg/newclient_update

changes from newclient
This commit is contained in:
Lennart Kats 2013-05-30 02:49:46 -07:00
commit cb6fce18b3
10 changed files with 46 additions and 104 deletions

View file

@ -627,9 +627,9 @@ var Document = function(text) {
var index = 0; var index = 0;
var row = Math.min(pos.row, lines.length); var row = Math.min(pos.row, lines.length);
for (var i = startRow || 0; i < row; ++i) for (var i = startRow || 0; i < row; ++i)
index += lines[i].length; index += lines[i].length + newlineLength;
return index + newlineLength * i + pos.column; return index + pos.column;
}; };
}).call(Document.prototype); }).call(Document.prototype);

View file

@ -332,7 +332,7 @@ function Folding() {
// Notify that fold data has changed. // Notify that fold data has changed.
this.$modified = true; this.$modified = true;
this._emit("changeFold", { data: fold }); this._emit("changeFold", { data: fold, action: "add" });
return fold; return fold;
}; };
@ -393,7 +393,7 @@ function Folding() {
// Notify that fold data has changed. // Notify that fold data has changed.
this.$modified = true; this.$modified = true;
this._emit("changeFold", { data: fold }); this._emit("changeFold", { data: fold, action: "remove" });
}; };
this.removeFolds = function(folds) { this.removeFolds = function(folds) {

View file

@ -51,6 +51,8 @@ AceEmmetEditor.prototype = {
setupContext: function(editor) { setupContext: function(editor) {
this.ace = editor; this.ace = editor;
this.indentation = editor.session.getTabString(); this.indentation = editor.session.getTabString();
if (!emmet)
emmet = window.emmet;
emmet.require("resources").setVariable("indentation", this.indentation); emmet.require("resources").setVariable("indentation", this.indentation);
this.$syntax = null; this.$syntax = null;
this.$syntax = this.getSyntax(); this.$syntax = this.getSyntax();
@ -161,7 +163,7 @@ AceEmmetEditor.prototype = {
*/ */
replaceContent: function(value, start, end, noIndent) { replaceContent: function(value, start, end, noIndent) {
if (end == null) if (end == null)
end = start == null ? content.length : start; end = start == null ? this.getContent().length : start;
if (start == null) if (start == null)
start = 0; start = 0;
var utils = emmet.require("utils"); var utils = emmet.require("utils");
@ -228,7 +230,7 @@ AceEmmetEditor.prototype = {
if (state.length > 1) if (state.length > 1)
syntax = state[0]; syntax = state[0];
else if (syntax == "php") else if (syntax == "php")
syntax = "html" syntax = "html";
} }
} }
return syntax; return syntax;
@ -309,12 +311,13 @@ var keymap = {
// update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"}, // update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"},
// expand_as_you_type: "ctrl+alt+enter", // expand_as_you_type: "ctrl+alt+enter",
// wrap_as_you_type: {"mac": "shift+ctrl+g", "win": "shift+ctrl+g"}, // wrap_as_you_type: {"mac": "shift+ctrl+g", "win": "shift+ctrl+g"},
expand_abbreviation_with_tab: "Tab" expand_abbreviation_with_tab: "Tab",
wrap_with_abbreviation: {"mac": "shift+ctrl+a", "win": "shift+ctrl+a"}
}; };
var editorProxy = new AceEmmetEditor(); var editorProxy = new AceEmmetEditor();
exports.commands = new HashHandler(); exports.commands = new HashHandler();
function runEmmetCommand(editor) { exports.runEmmetCommand = function(editor) {
editorProxy.setupContext(editor); editorProxy.setupContext(editor);
if (editorProxy.getSyntax() == "php") if (editorProxy.getSyntax() == "php")
return false; return false;
@ -325,6 +328,13 @@ function runEmmetCommand(editor) {
return false; return false;
} }
if (this.action == "wrap_with_abbreviation") {
// without setTimeout prompt doesn't work on firefox
return setTimeout(function() {
actions.run("wrap_with_abbreviation", editorProxy);
}, 0);
}
try { try {
var result = actions.run(this.action, editorProxy); var result = actions.run(this.action, editorProxy);
} catch(e) { } catch(e) {
@ -332,14 +342,14 @@ function runEmmetCommand(editor) {
console.log(e); console.log(e);
} }
return result; return result;
} };
for (var command in keymap) { for (var command in keymap) {
exports.commands.addCommand({ exports.commands.addCommand({
name: "emmet:" + command, name: "emmet:" + command,
action: command, action: command,
bindKey: keymap[command], bindKey: keymap[command],
exec: runEmmetCommand, exec: exports.runEmmetCommand,
multiSelectAction: "forEach" multiSelectAction: "forEach"
}); });
} }
@ -359,7 +369,7 @@ var onChangeMode = function(e, target) {
}; };
exports.AceEmmetEditor = AceEmmetEditor exports.AceEmmetEditor = AceEmmetEditor;
require("ace/config").defineOptions(Editor.prototype, "editor", { require("ace/config").defineOptions(Editor.prototype, "editor", {
enableEmmet: { enableEmmet: {
set: function(val) { set: function(val) {

View file

@ -70,7 +70,7 @@ oop.inherits(Mode, TextMode);
); );
this.lineCommentStart = ["#", "//"]; this.lineCommentStart = ["//", "#"];
this.blockComment = {start: "/*", end: "*/"}; this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {

View file

@ -75,7 +75,7 @@ oop.inherits(Mode, TextMode);
}; };
this.checkOutdent = function(state, line, input) { this.checkOutdent = function(state, line, input) {
return /\s+end$/.test(line + input) || /\s+}$/.test(line + input) || /\s+else$/.test(line + input); return /^\s+end$/.test(line + input) || /^\s+}$/.test(line + input) || /^\s+else$/.test(line + input);
}; };
this.autoOutdent = function(state, doc, row) { this.autoOutdent = function(state, doc, row) {

View file

@ -54,7 +54,7 @@ var VelocityHighlightRules = function() {
next : "style" next : "style"
}, { }, {
token : "meta.tag", // opening tag token : "meta.tag", // opening tag
regex : "<\\/?(?:[a-z])", regex : "<\\/?(?=[a-z])",
next : "tag" next : "tag"
}, { }, {
token : "comment", token : "comment",

View file

@ -283,7 +283,7 @@ var Search = function() {
}; };
}; };
this.$assembleRegExp = function(options) { this.$assembleRegExp = function(options, $disableFakeMultiline) {
if (options.needle instanceof RegExp) if (options.needle instanceof RegExp)
return options.re = options.needle; return options.re = options.needle;
@ -300,7 +300,7 @@ var Search = function() {
var modifier = options.caseSensitive ? "g" : "gi"; var modifier = options.caseSensitive ? "g" : "gi";
options.$isMultiLine = /[\n\r]/.test(needle); options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
if (options.$isMultiLine) if (options.$isMultiLine)
return options.re = this.$assembleMultilineRegExp(needle, modifier); return options.re = this.$assembleMultilineRegExp(needle, modifier);

View file

@ -349,6 +349,8 @@ var VirtualRenderer = function(container, theme) {
if (this.session.getUseWrapMode() && this.adjustWrapLimit()) if (this.session.getUseWrapMode() && this.adjustWrapLimit())
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
else
this.$loop.schedule(this.CHANGE_MARKER);
}; };
/** /**
@ -1270,12 +1272,14 @@ var VirtualRenderer = function(container, theme) {
afterLoad(theme); afterLoad(theme);
} }
function afterLoad(theme) { function afterLoad(module) {
if (!theme.cssClass) if (_self.$themeValue != theme)
return;
if (!module.cssClass)
return; return;
dom.importCssString( dom.importCssString(
theme.cssText, module.cssText,
theme.cssClass, module.cssClass,
_self.container.ownerDocument _self.container.ownerDocument
); );
@ -1283,13 +1287,13 @@ var VirtualRenderer = function(container, theme) {
dom.removeCssClass(_self.container, _self.theme.cssClass); dom.removeCssClass(_self.container, _self.theme.cssClass);
// this is kept only for backwards compatibility // this is kept only for backwards compatibility
_self.$theme = theme.cssClass; _self.$theme = module.cssClass;
_self.theme = theme; _self.theme = module;
dom.addCssClass(_self.container, theme.cssClass); dom.addCssClass(_self.container, module.cssClass);
dom.setCssClass(_self.container, "ace_dark", theme.isDark); dom.setCssClass(_self.container, "ace_dark", module.isDark);
var padding = theme.padding || 4; var padding = module.padding || 4;
if (_self.$padding && padding != _self.$padding) if (_self.$padding && padding != _self.$padding)
_self.setPadding(padding); _self.setPadding(padding);
@ -1299,7 +1303,7 @@ var VirtualRenderer = function(container, theme) {
_self.onResize(); _self.onResize();
} }
_self._dispatchEvent('themeLoaded',{theme:theme}); _self._dispatchEvent('themeLoaded',{theme:module});
} }
}; };

View file

@ -41,14 +41,15 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.onMessage = this.onMessage.bind(this); this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this); this.onError = this.onError.bind(this);
var workerUrl;
if (config.get("packaged")) {
workerUrl = config.moduleUrl(mod, "worker");
} else {
var normalizePath = this.$normalizePath;
// nameToUrl is renamed to toUrl in requirejs 2 // nameToUrl is renamed to toUrl in requirejs 2
if (require.nameToUrl && !require.toUrl) if (require.nameToUrl && !require.toUrl)
require.toUrl = require.nameToUrl; require.toUrl = require.nameToUrl;
var workerUrl;
if (config.get("packaged") || !require.toUrl) {
workerUrl = config.moduleUrl(mod, "worker");
} else {
var normalizePath = this.$normalizePath;
workerUrl = normalizePath(require.toUrl("ace/worker/worker.js", null, "_")); workerUrl = normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
var tlns = {}; var tlns = {};
@ -184,7 +185,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
var sender = Object.create(EventEmitter); var sender = Object.create(EventEmitter);
var _self = this; var _self = this;
this.$worker = {} this.$worker = {};
this.$worker.terminate = function() {}; this.$worker.terminate = function() {};
this.$worker.postMessage = function(e) { this.$worker.postMessage = function(e) {
_self.messageBuffer.push(e); _self.messageBuffer.push(e);

View file

@ -1,73 +0,0 @@
define(function(require, exports, module) {
"no use strict";
exports.main = function()
{
var console = {
log: function(msg) {
postMessage({type: "log", data: msg});
}
};
// NOTE: This sets the global `window` object used by workers.
// TODO: Pass into worker what it needs and don't set global here.
window = {
console: console
};
function initSender() {
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
var oop = require("ace/lib/oop");
var Sender = function() {};
(function() {
oop.implement(this, EventEmitter);
this.callback = function(data, callbackId) {
postMessage({
type: "call",
id: callbackId,
data: data
});
};
this.emit = function(name, data) {
postMessage({
type: "event",
name: name,
data: data
});
};
}).call(Sender.prototype);
return new Sender();
}
var main;
var sender;
onmessage = function(e) {
var msg = e.data;
if (msg.command) {
main[msg.command].apply(main, msg.args);
}
else if (msg.init) {
require("ace/lib/fixoldbrowsers");
sender = initSender();
require.async(msg.module, function(WORKER) {
var clazz = WORKER[msg.classname];
main = new clazz(sender);
});
}
else if (msg.event && sender) {
sender._emit(msg.event, msg.data);
}
};
}
});