From 87ff762270239a605172bd02921afe43295cc74c Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 26 Jan 2011 07:34:46 +0800 Subject: [PATCH 1/7] Pulling in jviereck's fixes for keyboard handling. --- lib/ace/keyboard/state_handler.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/ace/keyboard/state_handler.js b/lib/ace/keyboard/state_handler.js index ab50bc74..5861ad23 100644 --- a/lib/ace/keyboard/state_handler.js +++ b/lib/ace/keyboard/state_handler.js @@ -80,13 +80,13 @@ StateHandler.prototype = { } var keyArray = []; - if (hashId & 1) keyArray.push("Ctrl"); - if (hashId & 8) keyArray.push("Command"); - if (hashId & 2) keyArray.push("Option"); - if (hashId & 4) keyArray.push("Shift"); + if (hashId & 1) keyArray.push("ctrl"); + if (hashId & 8) keyArray.push("command"); + if (hashId & 2) keyArray.push("option"); + if (hashId & 4) keyArray.push("shift"); if (key) keyArray.push(key); - var symbolicName = keyArray.join("-").toLowerCase(); + var symbolicName = keyArray.join("-"); var bufferToUse = data.buffer + symbolicName; // Don't add the symbolic name to the key buffer if the alt_ key is @@ -194,6 +194,13 @@ StateHandler.prototype = { * This function is called by keyBinding. */ handleKeyboard: function(data, hashId, key) { + // If we pressed any command key but no other key, then ignore the input. + // Otherwise "shift-" is added to the buffer, and later on "shift-g" + // which results in "shift-shift-g" which doesn't make senese. + if (hashId != 0 && (key == "" || String.fromCharCode(0))) { + return null; + } + // Compute the current value of the keyboard input buffer. var r = this.$composeBuffer(data, hashId, key); var buffer = r.bufferToUse; From ce9d9f2bf4faf10ab66589f0dc104912a9f85a7d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 26 Jan 2011 12:13:43 +0100 Subject: [PATCH 2/7] Implementing CLI settings that are shown in the demo editor. Conflicts: support/pilot --- demo/boot.js | 6 +- lib/ace/defaults.js | 51 +++++++++++++++ lib/ace/settings/default-settings.js | 97 ++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 lib/ace/defaults.js create mode 100644 lib/ace/settings/default-settings.js diff --git a/demo/boot.js b/demo/boot.js index e84bfe3f..c5ca3b28 100644 --- a/demo/boot.js +++ b/demo/boot.js @@ -36,7 +36,7 @@ * ***** END LICENSE BLOCK ***** */ var config = { - paths: { + paths: { demo: "../demo", ace: "../lib/ace", cockpit: "../support/cockpit/lib/cockpit", @@ -47,10 +47,12 @@ var config = { var deps = [ "pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings", "pilot/environment", "demo/startup" ]; +var plugins = [ "pilot/index", "cockpit/index", "ace/defaults" ]; + require(config); require(deps, function() { var catalog = require("pilot/plugin_manager").catalog; - catalog.registerPlugins([ "pilot/index", "cockpit/index" ]).then(function() { + catalog.registerPlugins(plugins).then(function() { var env = require("pilot/environment").create(); catalog.startupPlugins({ env: env }).then(function() { require("demo/startup").launch(env); diff --git a/lib/ace/defaults.js b/lib/ace/defaults.js new file mode 100644 index 00000000..bd217cd1 --- /dev/null +++ b/lib/ace/defaults.js @@ -0,0 +1,51 @@ +/* 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): + * Irakli Gozalishvili (http://jeditoolkit.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 settings = require("ace/settings/default-settings") + +exports.startup = function startup(data, reason) { + settings.startup(data, reason) +} + +exports.shutdown = function shutdown(data, reason) { + settings.shutdown(data, reason) +} + +}) diff --git a/lib/ace/settings/default-settings.js b/lib/ace/settings/default-settings.js new file mode 100644 index 00000000..4e5e0fdf --- /dev/null +++ b/lib/ace/settings/default-settings.js @@ -0,0 +1,97 @@ +/* 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): + * Irakli Gozalishvili (http://jeditoolkit.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 types = require('pilot/types') +var SelectionType = require('pilot/types/basic').SelectionType + +var env + +var settingTypes = { + selectionStyle: new SelectionType({ + data: [ 'line', 'text' ] + }) +} + +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) + } + } +} + +exports.startup = function startup(data, reason) { + env = data.env + types.registerTypes(settingTypes) + data.env.settings.addSettings(settings) +} + +exports.shutdown = function shutdown(data, reason) { + data.env.settings.removeSettings(settings) +} + +}) From 9b0d7a6443f8f95d3e925e3710a505260e7fa35e Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 26 Jan 2011 12:15:01 +0100 Subject: [PATCH 3/7] update cockpit --- support/cockpit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/cockpit b/support/cockpit index dbc78536..1fa3516d 160000 --- a/support/cockpit +++ b/support/cockpit @@ -1 +1 @@ -Subproject commit dbc78536a4ea61e0f762067fb847213526500d9f +Subproject commit 1fa3516d4d553af9f6edd81c20023bcfab08c2a3 From 8508b43bb559b32754f244ae0ad415ce54d1e65f Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 26 Jan 2011 17:08:13 +0100 Subject: [PATCH 4/7] interpret undefined as false --- Makefile.dryice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.dryice.js b/Makefile.dryice.js index c60702a3..7674c8c7 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -263,7 +263,7 @@ function runFilters(value, filter, reading, name) { return value; } - if (filter.onRead == reading) { + if ((!!filter.onRead) == reading) { return filter(value, name); } else { From 4af6988ece312c11f48270d650d5359eda126446 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 26 Jan 2011 17:08:34 +0100 Subject: [PATCH 5/7] make build system worker compatible --- Makefile.dryice.js | 13 ++++- build_support/boot.js | 76 ++++++++++++------------ build_support/mini_require.js | 105 ++++++++++++++++++---------------- 3 files changed, 105 insertions(+), 89 deletions(-) diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 7674c8c7..74694852 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -91,11 +91,12 @@ copy({ { root: aceHome + '/lib', include: /.*\.js$/, - exclude: /tests?\/|theme\/|mode\// + exclude: /tests?\/|theme\/|mode\/|ace\/worker\/host\.js/ }, { base: aceHome + '/lib/', path: 'ace/theme/textmate.js' }, { base: aceHome + '/lib/', path: 'ace/mode/text.js' }, { base: aceHome + '/lib/', path: 'ace/mode/javascript.js' }, + { base: aceHome + '/lib/', path: 'ace/mode/javascript_worker.js' }, { base: aceHome + '/lib/', path: 'ace/mode/text_highlight_rules.js' }, { base: aceHome + '/lib/', path: 'ace/mode/javascript_highlight_rules.js' }, { base: aceHome + '/lib/', path: 'ace/mode/doc_comment_highlight_rules.js' }, @@ -121,7 +122,6 @@ copy({ source: [ 'build_support/mini_require.js', pilot, - // cockpit, ace, 'build_support/boot.js' ], @@ -146,7 +146,14 @@ copy({ dest: 'build/ace-uncompressed.js' }); - +// Create worker bootstrap code +copy({ + source: "lib/ace/worker/host.js", + filter: [function(data) { + return data + "\nimportScripts('ace-uncompressed.js')"; + }], + dest: 'build/host.js' +}); diff --git a/build_support/boot.js b/build_support/boot.js index f61e91d6..df2ab0ff 100644 --- a/build_support/boot.js +++ b/build_support/boot.js @@ -35,41 +35,45 @@ * * ***** END LICENSE BLOCK ***** */ -var deps = [ "pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings", - "pilot/environment" ]; - -require(deps, function() { - var catalog = require("pilot/plugin_manager").catalog; - catalog.registerPlugins([ "pilot/index" ]); -}); - -var ace = { - edit: function(el) { - if (typeof(el) == "string") { - el = document.getElementById(el); - } - var env = require("pilot/environment").create(); +// don't define it in a worker. +if (window.document) { + + var deps = [ "pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings", + "pilot/environment" ]; + + require(deps, function() { var catalog = require("pilot/plugin_manager").catalog; - catalog.startupPlugins({ env: env }).then(function() { - var EditSession = require("ace/edit_session").EditSession; - var JavaScriptMode = require("ace/mode/javascript").Mode; - var UndoManager = require("ace/undomanager").UndoManager; - var Editor = require("ace/editor").Editor; - var Renderer = require("ace/virtual_renderer").VirtualRenderer; - var theme = require("ace/theme/textmate"); - - var doc = new EditSession(el.innerHTML); - el.innerHTML = ''; - doc.setMode(new JavaScriptMode()); - doc.setUndoManager(new UndoManager()); - env.document = doc; - env.editor = new Editor(new Renderer(el, theme)); - env.editor.setSession(doc); - env.editor.resize(); - window.addEventListener("resize", function() { + catalog.registerPlugins([ "pilot/index" ]); + }); + + var ace = { + edit: function(el) { + if (typeof(el) == "string") { + el = document.getElementById(el); + } + var env = require("pilot/environment").create(); + var catalog = require("pilot/plugin_manager").catalog; + catalog.startupPlugins({ env: env }).then(function() { + var EditSession = require("ace/edit_session").EditSession; + var JavaScriptMode = require("ace/mode/javascript").Mode; + var UndoManager = require("ace/undomanager").UndoManager; + var Editor = require("ace/editor").Editor; + var Renderer = require("ace/virtual_renderer").VirtualRenderer; + var theme = require("ace/theme/textmate"); + + var doc = new EditSession(el.innerHTML); + el.innerHTML = ''; + doc.setMode(new JavaScriptMode()); + doc.setUndoManager(new UndoManager()); + env.document = doc; + env.editor = new Editor(new Renderer(el, theme)); + env.editor.setSession(doc); env.editor.resize(); - }, false); - el.env = env; - }); - } -}; + window.addEventListener("resize", function() { + env.editor.resize(); + }, false); + el.env = env; + }); + } + }; +} \ No newline at end of file diff --git a/build_support/mini_require.js b/build_support/mini_require.js index 9500fbc2..25069325 100644 --- a/build_support/mini_require.js +++ b/build_support/mini_require.js @@ -35,59 +35,64 @@ * * ***** END LICENSE BLOCK ***** */ -function require(module, callback) { +// don't define it in a worker. There we have a different implementation +if (window.document) { - if (Array.isArray(module)) { - var params = []; - module.forEach(function(m) { - params.push(require._lookup(m)); - }, this); - - if (callback) { - callback.apply(null, params); + window.require = function(module, callback) { + + if (Array.isArray(module)) { + var params = []; + module.forEach(function(m) { + params.push(require._lookup(m)); + }, this); + + if (callback) { + callback.apply(null, params); + } + } + + if (typeof module === 'string') { + payload = require._lookup(module); + if (callback) { + callback(); + } + return payload; } } - - if (typeof module === 'string') { - payload = require._lookup(module); - if (callback) { - callback(); + require.modules = {}; + require.packaged = true; + + require._lookup = function(moduleName) { + var payload = require.modules[moduleName]; + var module_name = moduleName; + if (payload == null) { + console.error('Missing module: ' + moduleName); + console.trace(); } + + if (typeof payload === 'function') { + var exports = {}; + var module = { + id: moduleName, + uri: '' + }; + payload(require, exports, module); + payload = exports; + // cache the resulting module object for next time + require.modules[module_name] = payload; + } + return payload; + }; + + window.define = function(module, payload) { + if (typeof module !== 'string') { + console.error('dropping module because define wasn\'t munged.'); + console.trace(); + return; + } + + // console.log('defining module: ' + module + ' as a ' + typeof payload); + require.modules[module] = payload; } -} -require.modules = {}; - -require._lookup = function(moduleName) { - var payload = require.modules[moduleName]; - var module_name = moduleName; - if (payload == null) { - console.error('Missing module: ' + moduleName); - console.trace(); - } - - if (typeof payload === 'function') { - var exports = {}; - var module = { - id: moduleName, - uri: '' - }; - payload(require, exports, module); - payload = exports; - // cache the resulting module object for next time - require.modules[module_name] = payload; - } - - return payload; -}; - -function define(module, payload) { - if (typeof module !== 'string') { - console.error('dropping module because define wasn\'t munged.'); - console.trace(); - return; - } - - // console.log('defining module: ' + module + ' as a ' + typeof payload); - require.modules[module] = payload; -} +} \ No newline at end of file From 23a2e368fc5be867f00fb84e18a9c5bbefa609b8 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 26 Jan 2011 17:09:32 +0100 Subject: [PATCH 6/7] make sure the worker also works with the packages version --- lib/ace/worker/host.js | 50 ++++++++++++++++++++++----------- lib/ace/worker/worker_client.js | 18 ++++++++---- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/lib/ace/worker/host.js b/lib/ace/worker/host.js index 7e182a38..cb449ffd 100644 --- a/lib/ace/worker/host.js +++ b/lib/ace/worker/host.js @@ -7,33 +7,48 @@ var window = { console: console }; -var require = function(name) { - if (require.modules[name]) - return require.modules[name].exports; +var require = function(id) { + var module = require.modules[id]; + if (module) { + if (!module.initialized) { + module.exports = module.factory().exports; + module.initialized = true; + } + return module.exports; + } - var chunks = name.split("/"); + var chunks = id.split("/"); chunks[0] = require.tlns[chunks[0]] || chunks[0]; path = require.baseUrl + "/" + chunks.join("/") + ".js" - require.id = name; - importScripts(path); - return require.modules[name].exports; + require.id = id; + importScripts(path); + return require(id); }; + require.modules = {}; require.tlns = {}; require.baseUrl; -var define = function(factory) { - var module = { - exports: {} +var define = function(id, factory) { + if (!factory) { + factory = id; + id = require.id; + } + if (id.indexOf("text!") == 0) + return; + + require.modules[id] = { + factory: function() { + var module = { + exports: {} + }; + var returnExports = factory(require, module.exports, module); + if (returnExports) + module.exports = exports; + return module; + } }; - - var name = require.id; - var returnExports = factory(require, module.exports, module); - if (returnExports) - module.exports = exports; - - require.modules[name] = module; }; function initBaseUrls(baseUrl, topLevelNamespaces) { @@ -81,6 +96,7 @@ onmessage = function(e) { main[msg.command].apply(main, msg.args); else if (msg.init) { initBaseUrls(msg.base, msg.tlns); + require("pilot/fixoldbrowsers"); sender = initSender(); var clazz = require(msg.module)[msg.classname]; main = new clazz(sender); diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 71d6505e..5e8e3c28 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -14,13 +14,19 @@ var EventEmitter = require("pilot/event_emitter").EventEmitter; var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) { this.callbacks = []; - var workerUrl = require.nameToUrl("ace/worker/host", null, "_"); - var worker = this.$worker = new Worker(workerUrl); - var tlns = {}; - for (var i=0; i Date: Wed, 26 Jan 2011 17:15:53 +0100 Subject: [PATCH 7/7] focus immediately and in a timeout --- lib/ace/editor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index efa1cb9a..6be9b875 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -221,6 +221,13 @@ var Editor =function(renderer, session) { }; this.focus = function() { + // Safari need the timeout + // iOS and Firefox need it called immediately + // to be on the save side we do both + var _self = this; + setTimeout(function() { + _self.textInput.focus(); + }); this.textInput.focus(); };