Merge branch 'master' of github.com:ajaxorg/ace

This commit is contained in:
Eddy Bruel 2010-11-02 15:15:31 +01:00
commit 04b4a59a81
5 changed files with 71 additions and 56 deletions

View file

@ -166,6 +166,40 @@ var Document = function(text, mode) {
this.$autoNewLine = "\n";
}
};
this.tokenRe = /^[\w\d]+/g;
this.nonTokenRe = /^[^\w\d]+/g;
this.getWordRange = function(row, column) {
var line = this.getLine(row);
var inToken = false;
if (column > 0) {
inToken = !!line.charAt(column - 1).match(this.tokenRe);
}
if (!inToken) {
inToken = !!line.charAt(column).match(this.tokenRe);
}
var re = inToken ? this.tokenRe : this.nonTokenRe;
var start = column;
if (start > 0) {
do {
start--;
}
while (start >= 0 && line.charAt(start).match(re));
start++;
}
var end = column;
while (end < line.length && line.charAt(end).match(re)) {
end++;
}
return new Range(row, start, row, end);
};
this.$getNewLineCharacter = function() {
switch (this.$newLineMode) {

View file

@ -37,8 +37,8 @@ var Editor = function(renderer, doc) {
var mouseTarget = renderer.getMouseEventTarget();
event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this));
event.addMultiMouseDownListener(mouseTarget, 2, 500, lang.bind(this.onMouseDoubleClick, this));
event.addMultiMouseDownListener(mouseTarget, 3, 600, lang.bind(this.onMouseTripleClick, this));
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, lang.bind(this.onMouseDoubleClick, this));
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, lang.bind(this.onMouseTripleClick, this));
event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this));
this.$selectionMarker = null;
@ -270,11 +270,15 @@ var Editor = function(renderer, doc) {
var pageX = event.getDocumentX(e);
var pageY = event.getDocumentY(e);
if (event.getButton(e) != 0)
return;
var pos = this.renderer.screenToTextCoordinates(pageX, pageY);
pos.row = Math.max(0, Math.min(pos.row, this.doc.getLength()-1));
if (event.getButton(e) != 0) {
if (this.selection.isEmpty()) {
this.moveCursorToPosition(pos);
}
return;
}
if (e.shiftKey)
this.selection.selectToPosition(pos)

View file

@ -198,9 +198,6 @@ var Selection = function(doc) {
this.$moveSelection(this.moveCursorFileStart);
};
this.tokenRe = /^[\w\d]+/g;
this.nonTokenRe = /^[^\w\d]+/g;
this.selectWordRight = function() {
this.$moveSelection(this.moveCursorWordRight);
};
@ -211,39 +208,14 @@ var Selection = function(doc) {
this.selectWord = function() {
var cursor = this.selectionLead;
var line = this.doc.getLine(cursor.row);
var column = cursor.column;
var inToken = false;
if (column > 0) {
inToken = !!line.charAt(column - 1).match(this.tokenRe);
}
if (!inToken) {
inToken = !!line.charAt(column).match(this.tokenRe);
}
var re = inToken ? this.tokenRe : this.nonTokenRe;
var start = column;
if (start > 0) {
do {
start--;
}
while (start >= 0 && line.charAt(start).match(re));
start++;
}
var end = column;
while (end < line.length && line.charAt(end).match(re)) {
end++;
}
this.setSelectionAnchor(cursor.row, start);
var range = this.doc.getWordRange(cursor.row, column);
this.setSelectionRange(range);
/*this.setSelectionAnchor(cursor.row, start);
this.$moveSelection(function() {
this.moveCursorTo(cursor.row, end);
});
});*/
};
this.selectLine = function() {
@ -317,20 +289,20 @@ var Selection = function(doc) {
var rightOfCursor = line.substring(column);
var match;
this.nonTokenRe.lastIndex = 0;
this.tokenRe.lastIndex = 0;
this.doc.nonTokenRe.lastIndex = 0;
this.doc.tokenRe.lastIndex = 0;
if (column == line.length) {
this.moveCursorRight();
return;
}
else if (match = this.nonTokenRe.exec(rightOfCursor)) {
column += this.nonTokenRe.lastIndex;
this.nonTokenRe.lastIndex = 0;
else if (match = this.doc.nonTokenRe.exec(rightOfCursor)) {
column += this.doc.nonTokenRe.lastIndex;
this.doc.nonTokenRe.lastIndex = 0;
}
else if (match = this.tokenRe.exec(rightOfCursor)) {
column += this.tokenRe.lastIndex;
this.tokenRe.lastIndex = 0;
else if (match = this.doc.tokenRe.exec(rightOfCursor)) {
column += this.doc.tokenRe.lastIndex;
this.doc.tokenRe.lastIndex = 0;
}
this.moveCursorTo(row, column);
@ -343,20 +315,20 @@ var Selection = function(doc) {
var leftOfCursor = lang.stringReverse(line.substring(0, column));
var match;
this.nonTokenRe.lastIndex = 0;
this.tokenRe.lastIndex = 0;
this.doc.nonTokenRe.lastIndex = 0;
this.doc.tokenRe.lastIndex = 0;
if (column == 0) {
this.moveCursorLeft();
return;
}
else if (match = this.nonTokenRe.exec(leftOfCursor)) {
column -= this.nonTokenRe.lastIndex;
this.nonTokenRe.lastIndex = 0;
else if (match = this.doc.nonTokenRe.exec(leftOfCursor)) {
column -= this.doc.nonTokenRe.lastIndex;
this.doc.nonTokenRe.lastIndex = 0;
}
else if (match = this.tokenRe.exec(leftOfCursor)) {
column -= this.tokenRe.lastIndex;
this.tokenRe.lastIndex = 0;
else if (match = this.doc.tokenRe.exec(leftOfCursor)) {
column -= this.doc.tokenRe.lastIndex;
this.doc.tokenRe.lastIndex = 0;
}
this.moveCursorTo(row, column);

View file

@ -158,7 +158,7 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
event.addListener(el, "mousewheel", listener);
};
event.addMultiMouseDownListener = function(el, count, timeout, callback) {
event.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
var clicks = 0;
var startX, startY;
@ -173,7 +173,8 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
}, timeout || 600);
}
if (Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
if (event.getButton(e) != button
|| Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
clicks = 0;
if (clicks == count) {

View file

@ -105,6 +105,10 @@
background: rgb(252, 255, 0);
}
.ace-tm .ace_marker-layer .ace_stack {
background: rgb(164, 229, 101);
}
.ace-tm .ace_marker-layer .ace_bracket {
margin: -1px 0 0 -1px;
border: 1px solid rgb(192, 192, 192);