From bf33db7e3e1192d5dbd195386ab1c3d997b91d91 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Thu, 17 Feb 2011 20:07:28 +0800 Subject: [PATCH 1/7] Make worker_client.$guessBasePath look for ace-uncompressed.js as well --- lib/ace/worker/worker_client.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 566498b5..5530240a 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -12,9 +12,9 @@ var oop = require("pilot/oop"); var EventEmitter = require("pilot/event_emitter").EventEmitter; var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) { - + this.callbacks = []; - + if (require.packaged) { var base = this.$guessBasePath(); var worker = this.$worker = new Worker(base + packagedJs); @@ -22,14 +22,14 @@ var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) { else { var workerUrl = require.nameToUrl("ace/worker/worker", null, "_"); var worker = this.$worker = new Worker(workerUrl); - + var tlns = {}; for (var i=0; i Date: Thu, 17 Feb 2011 15:38:40 +0100 Subject: [PATCH 2/7] fix undo cursor regression --- lib/ace/edit_session.js | 2 +- support/pilot | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 539ca1f2..f828b0df 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -593,7 +593,7 @@ var EditSession = function(text, mode) { if (action.isInsert) this.selection.setSelectionRange(Range.fromPoints(action.start, action.end)); else - this.selection.moveCursorToPosition(action.start); + this.selection.moveCursorToPosition(action.end); }, this.replace = function(range, text) { diff --git a/support/pilot b/support/pilot index 6e1fbe1d..cbfac498 160000 --- a/support/pilot +++ b/support/pilot @@ -1 +1 @@ -Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406 +Subproject commit cbfac498d30d43fdb7687d198c5b752736222c2f From 8e3c1e6096e97ba6c001196c67a822bf0fc2650d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 17 Feb 2011 16:11:03 +0100 Subject: [PATCH 3/7] let the document act as anchor factory --- lib/ace/document.js | 5 +++++ lib/ace/selection.js | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index e969e158..3fd06c53 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -40,6 +40,7 @@ define(function(require, exports, module) { var oop = require("pilot/oop"); var EventEmitter = require("pilot/event_emitter").EventEmitter; var Range = require("ace/range").Range; +var Anchor = require("ace/anchor").Anchor; var Document = function(text) { this.$lines = []; @@ -69,6 +70,10 @@ var Document = function(text) { this.getValue = function() { return this.getAllLines().join(this.getNewLineCharacter()); }; + + this.createAnchor = function(row, column) { + return new Anchor(this, row, column); + }; // check for IE split bug if ("aaa".split(/a/).length == 0) diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 408f044a..5c2a45bb 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -42,15 +42,14 @@ var oop = require("pilot/oop"); var lang = require("pilot/lang"); var EventEmitter = require("pilot/event_emitter").EventEmitter; var Range = require("ace/range").Range; -var Anchor = require("ace/anchor").Anchor; var Selection = function(session) { this.session = session; this.doc = session.getDocument(); this.clearSelection(); - this.selectionLead = new Anchor(this.doc, 0, 0); - this.selectionAnchor = new Anchor(this.doc, 0, 0); + this.selectionLead = this.doc.createAnchor(0, 0); + this.selectionAnchor = this.doc.createAnchor(0, 0); var _self = this; this.selectionLead.on("change", function(e) { From 537209da57aa08aee27064623bd5963ec14ac2b9 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 17 Feb 2011 18:00:57 +0100 Subject: [PATCH 4/7] explicitly update cursor on enter --- lib/ace/editor.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 69d5f5d9..676fe8ff 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -427,16 +427,18 @@ var Editor =function(renderer, session) { var lineIndent = this.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), this.session.getTabString()); var end = this.session.insert(cursor, text); - this.moveCursorToPosition(end); var lineState = this.bgTokenizer.getState(cursor.row); // TODO disabled multiline auto indent // possibly doing the indent before inserting the text // if (cursor.row !== end.row) { if (this.session.getDocument().isNewLine(text)) { + this.moveCursorTo(cursor.row+1, 0); + var size = this.session.getTabSize(), minIndent = Number.MAX_VALUE; + for (var row = cursor.row + 1; row <= end.row; ++row) { var indent = 0; From 848e29912cb3dd119bc4db4f9ec702aaa3c7c0a4 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Fri, 18 Feb 2011 04:46:28 +0800 Subject: [PATCH 5/7] Fix bug that prevented moveWordLeft/Right to move behind || or [ --- lib/ace/edit_session.js | 2 +- lib/ace/test/selection_test.js | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index f828b0df..d8cb4e30 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -286,7 +286,7 @@ var EditSession = function(text, mode) { }; this.tokenRe = /^[\w\d]+/g; - this.nonTokenRe = /^(?:[^\w\d|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF])+/g; + this.nonTokenRe = /^(?:[^\w\d]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF])+/g; this.getWordRange = function(row, column) { var line = this.getLine(row); diff --git a/lib/ace/test/selection_test.js b/lib/ace/test/selection_test.js index 445a0e72..b94a17db 100644 --- a/lib/ace/test/selection_test.js +++ b/lib/ace/test/selection_test.js @@ -287,6 +287,42 @@ var Test = { selection.moveCursorTo(0, 5); assert.notOk(called); + }, + + "test: moveWordLeft should move past || and [": function() { + var session = new EditSession("||foo["); + var selection = session.getSelection(); + + // Move behind || + selection.moveCursorWordRight(); + assert.position(selection.getCursor(), 0, 2); + + // Move beind foo + selection.moveCursorWordRight(); + assert.position(selection.getCursor(), 0, 5); + + // Move behind [ + selection.moveCursorWordRight(); + assert.position(selection.getCursor(), 0, 6); + }, + + "test: moveWordRight should move past || and [": function() { + var session = new EditSession("||foo["); + var selection = session.getSelection(); + + selection.moveCursorTo(0, 6); + + // Move behind [ + selection.moveCursorWordLeft(); + assert.position(selection.getCursor(), 0, 5); + + // Move beind foo + selection.moveCursorWordLeft(); + assert.position(selection.getCursor(), 0, 2); + + // Move behind || + selection.moveCursorWordLeft(); + assert.position(selection.getCursor(), 0, 0); } }; From 7ed9cb2f574bf21c6a5b7f00678ec42649059284 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Fri, 18 Feb 2011 06:29:40 +0800 Subject: [PATCH 6/7] Fix env.editor to point to the right object and add editor.env = env such that you can access env from the returned editor object --- build_support/boot.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build_support/boot.js b/build_support/boot.js index 8aafd2d9..0488fcae 100644 --- a/build_support/boot.js +++ b/build_support/boot.js @@ -50,38 +50,41 @@ var deps = [ require(deps, function() { var catalog = require("pilot/plugin_manager").catalog; catalog.registerPlugins([ "pilot/index" ]); - + var Dom = require("pilot/dom"); var Event = require("pilot/event"); - + var Editor = require("ace/editor").Editor; var EditSession = require("ace/edit_session").EditSession; var UndoManager = require("ace/undomanager").UndoManager; var Renderer = require("ace/virtual_renderer").VirtualRenderer; - + window.ace = { edit: function(el) { if (typeof(el) == "string") { el = document.getElementById(el); } - + var doc = new EditSession(Dom.getInnerText(el)); doc.setUndoManager(new UndoManager()); el.innerHTML = ''; var editor = new Editor(new Renderer(el, "ace/theme/textmate")); editor.setSession(doc); - + var env = require("pilot/environment").create(); catalog.startupPlugins({ env: env }).then(function() { env.document = doc; - env.editor = env; + env.editor = editor; editor.resize(); Event.addListener(window, "resize", function() { editor.resize(); }); el.env = env; }); + // Store env on editor such that it can be accessed later on from + // the returned object. + editor.env = env; return editor; } }; From f517bf97170a92ae553d1d2111089686bd3486a4 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Tue, 15 Feb 2011 03:40:11 +0800 Subject: [PATCH 7/7] Minimal UI for Find+Replace, issue 56. The API is there, the shortcut is there as well (Ctrl-R) but the command does not exist, so added a minimal implementation, just Find has one. --- lib/ace/commands/default_commands.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index e729457e..9a748a39 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -1,4 +1,5 @@ -/* ***** BEGIN LICENSE BLOCK ***** +/* 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 @@ -21,6 +22,7 @@ * Contributor(s): * Fabian Jakobs * Julian Viereck + * Mihai Sucan * * 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 @@ -82,6 +84,30 @@ canon.addCommand({ env.editor.find(needle); } }); +canon.addCommand({ + name: "replace", + exec: function(env, args, request) { + var needle = prompt("Find:"); + if (!needle) + return; + var replacement = prompt("Replacement:"); + if (!replacement) + return; + env.editor.replace(replacement, {needle: needle}); + } +}); +canon.addCommand({ + name: "replaceall", + exec: function(env, args, request) { + var needle = prompt("Find:"); + if (!needle) + return; + var replacement = prompt("Replacement:"); + if (!replacement) + return; + env.editor.replaceAll(replacement, {needle: needle}); + } +}); canon.addCommand({ name: "undo", exec: function(env, args, request) { env.editor.undo(); }