From 8530e3837ab66cc4c7fddac4c868b844d75f654b Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Mon, 27 May 2013 11:49:38 -0400 Subject: [PATCH 1/7] add wrap_with_abbreviation emmet command --- lib/ace/ext/emmet.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/ace/ext/emmet.js b/lib/ace/ext/emmet.js index d5296060..d6c141bf 100644 --- a/lib/ace/ext/emmet.js +++ b/lib/ace/ext/emmet.js @@ -51,6 +51,8 @@ AceEmmetEditor.prototype = { setupContext: function(editor) { this.ace = editor; this.indentation = editor.session.getTabString(); + if (!emmet) + emmet = window.emmet; emmet.require("resources").setVariable("indentation", this.indentation); this.$syntax = null; this.$syntax = this.getSyntax(); @@ -161,7 +163,7 @@ AceEmmetEditor.prototype = { */ replaceContent: function(value, start, end, noIndent) { if (end == null) - end = start == null ? content.length : start; + end = start == null ? this.getContent().length : start; if (start == null) start = 0; var utils = emmet.require("utils"); @@ -228,7 +230,7 @@ AceEmmetEditor.prototype = { if (state.length > 1) syntax = state[0]; else if (syntax == "php") - syntax = "html" + syntax = "html"; } } return syntax; @@ -309,12 +311,13 @@ var keymap = { // update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"}, // expand_as_you_type: "ctrl+alt+enter", // 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(); exports.commands = new HashHandler(); -function runEmmetCommand(editor) { +exports.runEmmetCommand = function(editor) { editorProxy.setupContext(editor); if (editorProxy.getSyntax() == "php") return false; @@ -325,6 +328,13 @@ function runEmmetCommand(editor) { 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 { var result = actions.run(this.action, editorProxy); } catch(e) { @@ -332,14 +342,14 @@ function runEmmetCommand(editor) { console.log(e); } return result; -} +}; for (var command in keymap) { exports.commands.addCommand({ name: "emmet:" + command, action: command, bindKey: keymap[command], - exec: runEmmetCommand, + exec: exports.runEmmetCommand, multiSelectAction: "forEach" }); } @@ -359,7 +369,7 @@ var onChangeMode = function(e, target) { }; -exports.AceEmmetEditor = AceEmmetEditor +exports.AceEmmetEditor = AceEmmetEditor; require("ace/config").defineOptions(Editor.prototype, "editor", { enableEmmet: { set: function(val) { From 60c882738c79c176443530c8ba0ea0c9546d9546 Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Mon, 27 May 2013 11:51:55 -0400 Subject: [PATCH 2/7] fix tag highlighting in velocity mode --- lib/ace/mode/velocity_highlight_rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/velocity_highlight_rules.js b/lib/ace/mode/velocity_highlight_rules.js index 07af2f92..9930d565 100644 --- a/lib/ace/mode/velocity_highlight_rules.js +++ b/lib/ace/mode/velocity_highlight_rules.js @@ -54,7 +54,7 @@ var VelocityHighlightRules = function() { next : "style" }, { token : "meta.tag", // opening tag - regex : "<\\/?(?:[a-z])", + regex : "<\\/?(?=[a-z])", next : "tag" }, { token : "comment", From 9a170dcd0348c3395e36efdd49a70db10d02707c Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Mon, 27 May 2013 12:08:45 -0400 Subject: [PATCH 3/7] do not throw if require.toUrl is missing --- lib/ace/worker/worker_client.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 6c849442..5a682fe5 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -41,14 +41,15 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { this.onMessage = this.onMessage.bind(this); this.onError = this.onError.bind(this); + // nameToUrl is renamed to toUrl in requirejs 2 + if (require.nameToUrl && !require.toUrl) + require.toUrl = require.nameToUrl; + var workerUrl; - if (config.get("packaged")) { + if (config.get("packaged") || !require.toUrl) { workerUrl = config.moduleUrl(mod, "worker"); } else { var normalizePath = this.$normalizePath; - // nameToUrl is renamed to toUrl in requirejs 2 - if (require.nameToUrl && !require.toUrl) - require.toUrl = require.nameToUrl; workerUrl = normalizePath(require.toUrl("ace/worker/worker.js", null, "_")); var tlns = {}; @@ -184,7 +185,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) { var sender = Object.create(EventEmitter); var _self = this; - this.$worker = {} + this.$worker = {}; this.$worker.terminate = function() {}; this.$worker.postMessage = function(e) { _self.messageBuffer.push(e); From cc27ed4efa17372d4be8b530b0e05e52152416b2 Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Mon, 27 May 2013 12:12:55 -0400 Subject: [PATCH 4/7] add action attribute to changeFold events --- lib/ace/edit_session/folding.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index f0fc274a..e85d4f0c 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -332,7 +332,7 @@ function Folding() { // Notify that fold data has changed. this.$modified = true; - this._emit("changeFold", { data: fold }); + this._emit("changeFold", { data: fold, action: "add" }); return fold; }; @@ -393,7 +393,7 @@ function Folding() { // Notify that fold data has changed. this.$modified = true; - this._emit("changeFold", { data: fold }); + this._emit("changeFold", { data: fold, action: "remove" }); }; this.removeFolds = function(folds) { From d40a9a228f500ad90c15557ef250c1853eb70b9f Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Mon, 27 May 2013 12:27:06 -0400 Subject: [PATCH 5/7] add changes from newclient --- lib/ace/document.js | 4 +- lib/ace/search.js | 4 +- lib/ace/virtual_renderer.js | 24 ++++++---- lib/ace/worker/worker_sourcemint.js | 73 ----------------------------- 4 files changed, 18 insertions(+), 87 deletions(-) delete mode 100644 lib/ace/worker/worker_sourcemint.js diff --git a/lib/ace/document.js b/lib/ace/document.js index 8a073f86..8db94078 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -627,9 +627,9 @@ var Document = function(text) { var index = 0; var row = Math.min(pos.row, lines.length); 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); diff --git a/lib/ace/search.js b/lib/ace/search.js index 63f46423..48cd88fb 100644 --- a/lib/ace/search.js +++ b/lib/ace/search.js @@ -283,7 +283,7 @@ var Search = function() { }; }; - this.$assembleRegExp = function(options) { + this.$assembleRegExp = function(options, $disableFakeMultiline) { if (options.needle instanceof RegExp) return options.re = options.needle; @@ -300,7 +300,7 @@ var Search = function() { var modifier = options.caseSensitive ? "g" : "gi"; - options.$isMultiLine = /[\n\r]/.test(needle); + options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle); if (options.$isMultiLine) return options.re = this.$assembleMultilineRegExp(needle, modifier); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 9d0d1b1d..8449b958 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -349,6 +349,8 @@ var VirtualRenderer = function(container, theme) { if (this.session.getUseWrapMode() && this.adjustWrapLimit()) this.$loop.schedule(this.CHANGE_FULL); + else + this.$loop.schedule(this.CHANGE_MARKER); }; /** @@ -1270,12 +1272,14 @@ var VirtualRenderer = function(container, theme) { afterLoad(theme); } - function afterLoad(theme) { - if (!theme.cssClass) + function afterLoad(module) { + if (_self.$themeValue != theme) + return; + if (!module.cssClass) return; dom.importCssString( - theme.cssText, - theme.cssClass, + module.cssText, + module.cssClass, _self.container.ownerDocument ); @@ -1283,13 +1287,13 @@ var VirtualRenderer = function(container, theme) { dom.removeCssClass(_self.container, _self.theme.cssClass); // this is kept only for backwards compatibility - _self.$theme = theme.cssClass; + _self.$theme = module.cssClass; - _self.theme = theme; - dom.addCssClass(_self.container, theme.cssClass); - dom.setCssClass(_self.container, "ace_dark", theme.isDark); + _self.theme = module; + dom.addCssClass(_self.container, module.cssClass); + dom.setCssClass(_self.container, "ace_dark", module.isDark); - var padding = theme.padding || 4; + var padding = module.padding || 4; if (_self.$padding && padding != _self.$padding) _self.setPadding(padding); @@ -1299,7 +1303,7 @@ var VirtualRenderer = function(container, theme) { _self.onResize(); } - _self._dispatchEvent('themeLoaded',{theme:theme}); + _self._dispatchEvent('themeLoaded',{theme:module}); } }; diff --git a/lib/ace/worker/worker_sourcemint.js b/lib/ace/worker/worker_sourcemint.js deleted file mode 100644 index bc305b79..00000000 --- a/lib/ace/worker/worker_sourcemint.js +++ /dev/null @@ -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); - } - }; - } -}); From 261e6cfc0533288f5816169192ec81be0cd7a2b0 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 28 May 2013 23:48:27 +0400 Subject: [PATCH 6/7] fix ruby unindent behavior fixes #1451 --- lib/ace/mode/ruby.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/ruby.js b/lib/ace/mode/ruby.js index 1c6d63f6..073fa070 100644 --- a/lib/ace/mode/ruby.js +++ b/lib/ace/mode/ruby.js @@ -75,7 +75,7 @@ oop.inherits(Mode, TextMode); }; 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) { From 9bed019fee9634d728602959e3e4e60aef859526 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 May 2013 16:08:57 +0400 Subject: [PATCH 7/7] prefer // comment in php --- lib/ace/mode/php.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index 87b70cbd..8e3ecd6c 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -70,7 +70,7 @@ oop.inherits(Mode, TextMode); ); - this.lineCommentStart = ["#", "//"]; + this.lineCommentStart = ["//", "#"]; this.blockComment = {start: "/*", end: "*/"}; this.getNextLineIndent = function(state, line, tab) {