Merge branch 'master' of https://github.com/ajaxorg/ace
This commit is contained in:
commit
b6653bbc29
9 changed files with 95 additions and 22 deletions
|
|
@ -75,13 +75,16 @@ require(deps, function() {
|
||||||
var env = require("pilot/environment").create();
|
var env = require("pilot/environment").create();
|
||||||
catalog.startupPlugins({ env: env }).then(function() {
|
catalog.startupPlugins({ env: env }).then(function() {
|
||||||
env.document = doc;
|
env.document = doc;
|
||||||
env.editor = env;
|
env.editor = editor;
|
||||||
editor.resize();
|
editor.resize();
|
||||||
Event.addListener(window, "resize", function() {
|
Event.addListener(window, "resize", function() {
|
||||||
editor.resize();
|
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;
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
|
@ -21,6 +22,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
* Julian Viereck <julian.viereck@gmail.com>
|
* Julian Viereck <julian.viereck@gmail.com>
|
||||||
|
* Mihai Sucan <mihai.sucan@gmail.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* 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
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
|
@ -82,6 +84,30 @@ canon.addCommand({
|
||||||
env.editor.find(needle);
|
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({
|
canon.addCommand({
|
||||||
name: "undo",
|
name: "undo",
|
||||||
exec: function(env, args, request) { env.editor.undo(); }
|
exec: function(env, args, request) { env.editor.undo(); }
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ define(function(require, exports, module) {
|
||||||
var oop = require("pilot/oop");
|
var oop = require("pilot/oop");
|
||||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||||
var Range = require("ace/range").Range;
|
var Range = require("ace/range").Range;
|
||||||
|
var Anchor = require("ace/anchor").Anchor;
|
||||||
|
|
||||||
var Document = function(text) {
|
var Document = function(text) {
|
||||||
this.$lines = [];
|
this.$lines = [];
|
||||||
|
|
@ -70,6 +71,10 @@ var Document = function(text) {
|
||||||
return this.getAllLines().join(this.getNewLineCharacter());
|
return this.getAllLines().join(this.getNewLineCharacter());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.createAnchor = function(row, column) {
|
||||||
|
return new Anchor(this, row, column);
|
||||||
|
};
|
||||||
|
|
||||||
// check for IE split bug
|
// check for IE split bug
|
||||||
if ("aaa".split(/a/).length == 0)
|
if ("aaa".split(/a/).length == 0)
|
||||||
this.$split = function(text) {
|
this.$split = function(text) {
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ var EditSession = function(text, mode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.tokenRe = /^[\w\d]+/g;
|
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) {
|
this.getWordRange = function(row, column) {
|
||||||
var line = this.getLine(row);
|
var line = this.getLine(row);
|
||||||
|
|
@ -593,7 +593,7 @@ var EditSession = function(text, mode) {
|
||||||
if (action.isInsert)
|
if (action.isInsert)
|
||||||
this.selection.setSelectionRange(Range.fromPoints(action.start, action.end));
|
this.selection.setSelectionRange(Range.fromPoints(action.start, action.end));
|
||||||
else
|
else
|
||||||
this.selection.moveCursorToPosition(action.start);
|
this.selection.moveCursorToPosition(action.end);
|
||||||
},
|
},
|
||||||
|
|
||||||
this.replace = function(range, text) {
|
this.replace = function(range, text) {
|
||||||
|
|
|
||||||
|
|
@ -427,16 +427,18 @@ var Editor =function(renderer, session) {
|
||||||
var lineIndent = this.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), this.session.getTabString());
|
var lineIndent = this.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), this.session.getTabString());
|
||||||
var end = this.session.insert(cursor, text);
|
var end = this.session.insert(cursor, text);
|
||||||
|
|
||||||
this.moveCursorToPosition(end);
|
|
||||||
|
|
||||||
var lineState = this.bgTokenizer.getState(cursor.row);
|
var lineState = this.bgTokenizer.getState(cursor.row);
|
||||||
// TODO disabled multiline auto indent
|
// TODO disabled multiline auto indent
|
||||||
// possibly doing the indent before inserting the text
|
// possibly doing the indent before inserting the text
|
||||||
// if (cursor.row !== end.row) {
|
// if (cursor.row !== end.row) {
|
||||||
if (this.session.getDocument().isNewLine(text)) {
|
if (this.session.getDocument().isNewLine(text)) {
|
||||||
|
this.moveCursorTo(cursor.row+1, 0);
|
||||||
|
|
||||||
var size = this.session.getTabSize(),
|
var size = this.session.getTabSize(),
|
||||||
minIndent = Number.MAX_VALUE;
|
minIndent = Number.MAX_VALUE;
|
||||||
|
|
||||||
|
|
||||||
for (var row = cursor.row + 1; row <= end.row; ++row) {
|
for (var row = cursor.row + 1; row <= end.row; ++row) {
|
||||||
var indent = 0;
|
var indent = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,15 +42,14 @@ var oop = require("pilot/oop");
|
||||||
var lang = require("pilot/lang");
|
var lang = require("pilot/lang");
|
||||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||||
var Range = require("ace/range").Range;
|
var Range = require("ace/range").Range;
|
||||||
var Anchor = require("ace/anchor").Anchor;
|
|
||||||
|
|
||||||
var Selection = function(session) {
|
var Selection = function(session) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.doc = session.getDocument();
|
this.doc = session.getDocument();
|
||||||
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.selectionLead = new Anchor(this.doc, 0, 0);
|
this.selectionLead = this.doc.createAnchor(0, 0);
|
||||||
this.selectionAnchor = new Anchor(this.doc, 0, 0);
|
this.selectionAnchor = this.doc.createAnchor(0, 0);
|
||||||
|
|
||||||
var _self = this;
|
var _self = this;
|
||||||
this.selectionLead.on("change", function(e) {
|
this.selectionLead.on("change", function(e) {
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,42 @@ var Test = {
|
||||||
|
|
||||||
selection.moveCursorTo(0, 5);
|
selection.moveCursorTo(0, 5);
|
||||||
assert.notOk(called);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,11 @@ var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) {
|
||||||
this.$guessBasePath = function() {
|
this.$guessBasePath = function() {
|
||||||
var scripts = document.getElementsByTagName("script");
|
var scripts = document.getElementsByTagName("script");
|
||||||
for (var i=0; i<scripts.length; i++) {
|
for (var i=0; i<scripts.length; i++) {
|
||||||
var m = scripts[i].src.match(/^(.*\/)ace\.js$/);
|
var m = scripts[i].src.
|
||||||
if (m)
|
match(/^(.*\/)ace\.js$|^(.*\/)ace-uncompressed\.js$/);
|
||||||
return m[1];
|
if (m) {
|
||||||
|
return m[1] || m[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406
|
Subproject commit cbfac498d30d43fdb7687d198c5b752736222c2f
|
||||||
Loading…
Add table
Add a link
Reference in a new issue