make jslint happy

This commit is contained in:
Fabian Jakobs 2010-04-12 13:10:47 +02:00
commit 443b712b8f
15 changed files with 968 additions and 949 deletions

View file

@ -1,3 +1,3 @@
onmessage = function(e) { onmessage = function(e) {
onmessage = new Function("e", e.data); onmessage = new Function("e", e.data);
} };

View file

@ -45,7 +45,7 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete) {
self.onUpdate(startLine, textLines.length - 1); self.onUpdate(startLine, textLines.length - 1);
self.onComplete(); self.onComplete();
} };
}; };
ace.BackgroundTokenizer.prototype.setLines = function(textLines) { ace.BackgroundTokenizer.prototype.setLines = function(textLines) {

View file

@ -10,7 +10,7 @@ ace.CursorLayer = function(parentEl) {
this.cursor.className = "cursor"; this.cursor.className = "cursor";
this.isVisible = false; this.isVisible = false;
} };
ace.CursorLayer.prototype.setCursor = function(position) { ace.CursorLayer.prototype.setCursor = function(position) {
this.position = { this.position = {
@ -47,7 +47,7 @@ ace.CursorLayer.prototype.getPixelPosition = function() {
left : 0, left : 0,
top : 0 top : 0
}; };
} };
ace.CursorLayer.prototype.update = function(config) { ace.CursorLayer.prototype.update = function(config) {
if (!this.position) if (!this.position)

View file

@ -3,7 +3,7 @@ if (!window.ace)
(function() { (function() {
var keys = { var keys = {
UP : 38, UP : 38,
RIGHT : 39, RIGHT : 39,
DOWN : 40, DOWN : 40,
@ -16,9 +16,9 @@ var keys = {
BACKSPACE : 8, BACKSPACE : 8,
TAB : 9, TAB : 9,
A : 65 A : 65
} };
var KeyBinding = function(element, host) { var KeyBinding = function(element, host) {
ace.addListener(element, "keydown", function(e) { ace.addListener(element, "keydown", function(e) {
var key = e.keyCode; var key = e.keyCode;
@ -31,7 +31,10 @@ var KeyBinding = function(element, host) {
break; break;
case keys.UP: case keys.UP:
if (e.metaKey) { if (e.metaKey && e.shiftKey) {
host.selectFileStart();
}
else if (e.metaKey) {
host.navigateFileStart(); host.navigateFileStart();
} }
if (e.shiftKey) { if (e.shiftKey) {
@ -43,7 +46,10 @@ var KeyBinding = function(element, host) {
return ace.stopEvent(e); return ace.stopEvent(e);
case keys.DOWN: case keys.DOWN:
if (e.metaKey) { if (e.metaKey && e.shiftKey) {
host.selectFileEnd();
}
else if (e.metaKey) {
host.navigateFileEnd(); host.navigateFileEnd();
} }
if (e.shiftKey) { if (e.shiftKey) {
@ -133,9 +139,9 @@ var KeyBinding = function(element, host) {
return ace.stopEvent(e); return ace.stopEvent(e);
} }
}); });
}; };
ace.Editor = function(doc, renderer) { ace.Editor = function(doc, renderer) {
var container = renderer.getContainerElement(); var container = renderer.getContainerElement();
this.renderer = renderer; this.renderer = renderer;
@ -170,36 +176,36 @@ ace.Editor = function(doc, renderer) {
this.selection = null; this.selection = null;
this.renderer.draw(); this.renderer.draw();
}; };
ace.Editor.prototype.resize = function() { ace.Editor.prototype.resize = function() {
this.renderer.draw(); this.renderer.draw();
}; };
ace.Editor.prototype.updateCursor = function() { ace.Editor.prototype.updateCursor = function() {
this.renderer.updateCursor(this.cursor); this.renderer.updateCursor(this.cursor);
}; };
ace.Editor.prototype.onFocus = function() { ace.Editor.prototype.onFocus = function() {
this.renderer.showCursor(); this.renderer.showCursor();
this.renderer.visualizeFocus(); this.renderer.visualizeFocus();
}; };
ace.Editor.prototype.onBlur = function() { ace.Editor.prototype.onBlur = function() {
this.renderer.hideCursor(); this.renderer.hideCursor();
this.renderer.visualizeBlur(); this.renderer.visualizeBlur();
}; };
ace.Editor.prototype.onDocumentChange = function(startRow, endRow) { ace.Editor.prototype.onDocumentChange = function(startRow, endRow) {
this.tokenizer.start(startRow); this.tokenizer.start(startRow);
this.renderer.updateLines(startRow, endRow); this.renderer.updateLines(startRow, endRow);
}; };
ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) { ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) {
this.renderer.updateLines(startRow, endRow); this.renderer.updateLines(startRow, endRow);
}; };
ace.Editor.prototype.onMouseDown = function(e) { ace.Editor.prototype.onMouseDown = function(e) {
this.textInput.focus(); this.textInput.focus();
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY); var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
@ -236,9 +242,9 @@ ace.Editor.prototype.onMouseDown = function(e) {
var timerId = setInterval(onSelectionInterval, 20); var timerId = setInterval(onSelectionInterval, 20);
return ace.preventDefault(e); return ace.preventDefault(e);
}; };
ace.Editor.prototype.onMouseDoubleClick = function(e) { ace.Editor.prototype.onMouseDoubleClick = function(e) {
var line = this.doc.getLine(this.cursor.row); var line = this.doc.getLine(this.cursor.row);
var column = this.cursor.column; var column = this.cursor.column;
@ -261,7 +267,7 @@ ace.Editor.prototype.onMouseDoubleClick = function(e) {
do { do {
start--; start--;
} }
while (start >= 0 && line.charAt(start).match(re)) while (start >= 0 && line.charAt(start).match(re));
start++; start++;
} }
@ -274,32 +280,32 @@ ace.Editor.prototype.onMouseDoubleClick = function(e) {
this._moveSelection(function() { this._moveSelection(function() {
this.moveCursorTo(this.cursor.row, end); this.moveCursorTo(this.cursor.row, end);
}); });
}; };
ace.Editor.prototype.onMouseWheel = function(e) { ace.Editor.prototype.onMouseWheel = function(e) {
var delta = e.wheel; var delta = e.wheel;
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15)); this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
return ace.preventDefault(e); return ace.preventDefault(e);
}; };
ace.Editor.prototype.getCopyText = function() { ace.Editor.prototype.getCopyText = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
return this.doc.getTextRange(this.getSelectionRange()); return this.doc.getTextRange(this.getSelectionRange());
} }
else { else {
return ""; return "";
} }
}; };
ace.Editor.prototype.onCut = function() { ace.Editor.prototype.onCut = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
this.cursor = this.doc.remove(this.getSelectionRange()); this.cursor = this.doc.remove(this.getSelectionRange());
this.clearSelection(); this.clearSelection();
this.renderer.updateCursor(this.cursor); this.renderer.updateCursor(this.cursor);
} }
}; };
ace.Editor.prototype.onTextInput = function(text) { ace.Editor.prototype.onTextInput = function(text) {
if (this.hasSelection()) { if (this.hasSelection()) {
this.cursor = this.doc.replace(this.getSelectionRange(), text); this.cursor = this.doc.replace(this.getSelectionRange(), text);
this.clearSelection(); this.clearSelection();
@ -309,9 +315,9 @@ ace.Editor.prototype.onTextInput = function(text) {
} }
this.renderer.updateCursor(this.cursor); this.renderer.updateCursor(this.cursor);
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.removeRight = function() { ace.Editor.prototype.removeRight = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
this.cursor = this.doc.remove(this.getSelectionRange()); this.cursor = this.doc.remove(this.getSelectionRange());
this.renderer.updateCursor(this.cursor); this.renderer.updateCursor(this.cursor);
@ -321,7 +327,7 @@ ace.Editor.prototype.removeRight = function() {
var rangeEnd = { var rangeEnd = {
row : this.cursor.row, row : this.cursor.row,
column : this.cursor.column + 1 column : this.cursor.column + 1
} };
if (rangeEnd.column > this.doc.getLine(this.cursor.row).length) { if (rangeEnd.column > this.doc.getLine(this.cursor.row).length) {
rangeEnd.row += 1; rangeEnd.row += 1;
rangeEnd.column = 0; rangeEnd.column = 0;
@ -333,7 +339,7 @@ ace.Editor.prototype.removeRight = function() {
} }
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.removeLeft = function() { ace.Editor.prototype.removeLeft = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
@ -346,7 +352,7 @@ ace.Editor.prototype.removeRight = function() {
var rangeStart = { var rangeStart = {
row : this.cursor.row, row : this.cursor.row,
column : this.cursor.column + -1 column : this.cursor.column + -1
} };
if (rangeStart.column < 0) { if (rangeStart.column < 0) {
rangeStart.row -= 1; rangeStart.row -= 1;
rangeStart.column = this.doc rangeStart.column = this.doc
@ -367,59 +373,59 @@ ace.Editor.prototype.removeRight = function() {
this.onTextInput(" "); this.onTextInput(" ");
}; };
ace.Editor.prototype.onCompositionUpdate = function(text) { ace.Editor.prototype.onCompositionUpdate = function(text) {
this.renderer.setCompositionText(text); this.renderer.setCompositionText(text);
}; };
ace.Editor.prototype.onCompositionEnd = function() { ace.Editor.prototype.onCompositionEnd = function() {
this.renderer.hideComposition(); this.renderer.hideComposition();
this.removeLeft(); this.removeLeft();
}; };
ace.Editor.prototype.getFirstVisibleRow = function() { ace.Editor.prototype.getFirstVisibleRow = function() {
return this.renderer.getFirstVisibleRow(); return this.renderer.getFirstVisibleRow();
}; };
ace.Editor.prototype.getLastVisibleRow = function() { ace.Editor.prototype.getLastVisibleRow = function() {
return this.renderer.getLastVisibleRow(); return this.renderer.getLastVisibleRow();
}; };
ace.Editor.prototype.getPageDownRow = function() { ace.Editor.prototype.getPageDownRow = function() {
return this.renderer.getLastVisibleRow() - 1; return this.renderer.getLastVisibleRow() - 1;
}; };
ace.Editor.prototype.getPageUpRow = function() { ace.Editor.prototype.getPageUpRow = function() {
var firstRow = this.renderer.getFirstVisibleRow(); var firstRow = this.renderer.getFirstVisibleRow();
var lastRow = this.renderer.getLastVisibleRow(); var lastRow = this.renderer.getLastVisibleRow();
return firstRow - (lastRow - firstRow) + 1; return firstRow - (lastRow - firstRow) + 1;
}; };
ace.Editor.prototype.scrollPageDown = function() { ace.Editor.prototype.scrollPageDown = function() {
this.scrollToRow(this.getPageDownRow()); this.scrollToRow(this.getPageDownRow());
}; };
ace.Editor.prototype.scrollPageUp = function() { ace.Editor.prototype.scrollPageUp = function() {
this.renderer.scrollToRow(this.getPageUpRow()); this.renderer.scrollToRow(this.getPageUpRow());
}; };
ace.Editor.prototype.scrollToRow = function(row) { ace.Editor.prototype.scrollToRow = function(row) {
this.renderer.scrollToRow(row); this.renderer.scrollToRow(row);
}; };
ace.Editor.prototype.navigateUp = function() { ace.Editor.prototype.navigateUp = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorUp(); this.moveCursorUp();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.navigateDown = function() { ace.Editor.prototype.navigateDown = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorDown(); this.moveCursorDown();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.navigateLeft = function() { ace.Editor.prototype.navigateLeft = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
var selectionStart = this.getSelectionRange().start; var selectionStart = this.getSelectionRange().start;
this.moveCursorTo(selectionStart.row, selectionStart.column); this.moveCursorTo(selectionStart.row, selectionStart.column);
@ -430,9 +436,9 @@ ace.Editor.prototype.navigateLeft = function() {
this.clearSelection(); this.clearSelection();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.navigateRight = function() { ace.Editor.prototype.navigateRight = function() {
if (this.hasSelection()) { if (this.hasSelection()) {
var selectionEnd = this.getSelectionRange().end; var selectionEnd = this.getSelectionRange().end;
this.moveCursorTo(selectionEnd.row, selectionEnd.column); this.moveCursorTo(selectionEnd.row, selectionEnd.column);
@ -443,41 +449,41 @@ ace.Editor.prototype.navigateRight = function() {
this.clearSelection(); this.clearSelection();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}, },
ace.Editor.prototype.navigateLineStart = function() { ace.Editor.prototype.navigateLineStart = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorLineStart(); this.moveCursorLineStart();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.navigateLineEnd = function() { ace.Editor.prototype.navigateLineEnd = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorLineEnd(); this.moveCursorLineEnd();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.navigateFileEnd = function() { ace.Editor.prototype.navigateFileEnd = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorFileEnd(); this.moveCursorFileEnd();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}, },
ace.Editor.prototype.navigateFileStart = function() { ace.Editor.prototype.navigateFileStart = function() {
this.clearSelection(); this.clearSelection();
this.moveCursorFileStart(); this.moveCursorFileStart();
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}, },
ace.Editor.prototype.moveCursorUp = function() { ace.Editor.prototype.moveCursorUp = function() {
this.moveCursorBy(-1, 0); this.moveCursorBy(-1, 0);
}; };
ace.Editor.prototype.moveCursorDown = function() { ace.Editor.prototype.moveCursorDown = function() {
this.moveCursorBy(1, 0); this.moveCursorBy(1, 0);
}; };
ace.Editor.prototype.moveCursorLeft = function() { ace.Editor.prototype.moveCursorLeft = function() {
if (this.cursor.column == 0) { if (this.cursor.column == 0) {
if (this.cursor.row > 0) { if (this.cursor.row > 0) {
this.moveCursorTo(this.cursor.row - 1, this.doc this.moveCursorTo(this.cursor.row - 1, this.doc
@ -487,9 +493,9 @@ ace.Editor.prototype.moveCursorLeft = function() {
else { else {
this.moveCursorBy(0, -1); this.moveCursorBy(0, -1);
} }
}; };
ace.Editor.prototype.moveCursorRight = function() { ace.Editor.prototype.moveCursorRight = function() {
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) { if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
if (this.cursor.row < this.doc.getLength() - 1) { if (this.cursor.row < this.doc.getLength() - 1) {
this.moveCursorTo(this.cursor.row + 1, 0); this.moveCursorTo(this.cursor.row + 1, 0);
@ -498,32 +504,32 @@ ace.Editor.prototype.moveCursorRight = function() {
else { else {
this.moveCursorBy(0, 1); this.moveCursorBy(0, 1);
} }
}; };
ace.Editor.prototype.moveCursorLineStart = function() { ace.Editor.prototype.moveCursorLineStart = function() {
this.moveCursorTo(this.cursor.row, 0); this.moveCursorTo(this.cursor.row, 0);
}; };
ace.Editor.prototype.moveCursorLineEnd = function() { ace.Editor.prototype.moveCursorLineEnd = function() {
this.moveCursorTo(this.cursor.row, this.moveCursorTo(this.cursor.row,
this.doc.getLine(this.cursor.row).length); this.doc.getLine(this.cursor.row).length);
}; };
ace.Editor.prototype.moveCursorFileEnd = function() { ace.Editor.prototype.moveCursorFileEnd = function() {
var row = this.doc.getLength() - 1; var row = this.doc.getLength() - 1;
var column = this.doc.getLine(row).length; var column = this.doc.getLine(row).length;
this.moveCursorTo(row, column); this.moveCursorTo(row, column);
}; };
ace.Editor.prototype.moveCursorFileStart = function() { ace.Editor.prototype.moveCursorFileStart = function() {
this.moveCursorTo(0, 0); this.moveCursorTo(0, 0);
}; };
ace.Editor.prototype.moveCursorBy = function(rows, chars) { ace.Editor.prototype.moveCursorBy = function(rows, chars) {
this.moveCursorTo(this.cursor.row + rows, this.cursor.column + chars); this.moveCursorTo(this.cursor.row + rows, this.cursor.column + chars);
}; };
ace.Editor.prototype.moveCursorTo = function(row, column) { ace.Editor.prototype.moveCursorTo = function(row, column) {
if (row >= this.doc.getLength()) { if (row >= this.doc.getLength()) {
this.cursor.row = this.doc.getLength() - 1; this.cursor.row = this.doc.getLength() - 1;
this.cursor.column = this.doc.getLine(this.cursor.row).length; this.cursor.column = this.doc.getLine(this.cursor.row).length;
@ -539,20 +545,20 @@ ace.Editor.prototype.moveCursorTo = function(row, column) {
.max(0, column)); .max(0, column));
} }
this.updateCursor(); this.updateCursor();
}; };
ace.Editor.prototype.getCursorPosition = function() { ace.Editor.prototype.getCursorPosition = function() {
return { return {
row : this.cursor.row, row : this.cursor.row,
column : this.cursor.column column : this.cursor.column
} };
}; };
ace.Editor.prototype.hasSelection = function() { ace.Editor.prototype.hasSelection = function() {
return !!this.selectionLead; return !!this.selectionLead;
}; };
ace.Editor.prototype.setSelectionAnchor = function(row, column) { ace.Editor.prototype.setSelectionAnchor = function(row, column) {
this.clearSelection(); this.clearSelection();
this.selectionAnchor = { this.selectionAnchor = {
@ -562,9 +568,9 @@ ace.Editor.prototype.setSelectionAnchor = function(row, column) {
}; };
this.selectionLead = null; this.selectionLead = null;
}; };
ace.Editor.prototype.getSelectionRange = function() { ace.Editor.prototype.getSelectionRange = function() {
var anchor = this.selectionAnchor; var anchor = this.selectionAnchor;
var lead = this.selectionLead; var lead = this.selectionLead;
@ -577,18 +583,18 @@ ace.Editor.prototype.getSelectionRange = function() {
return { return {
start : lead, start : lead,
end : anchor end : anchor
} };
} }
else { else {
return { return {
start : anchor, start : anchor,
end : lead end : lead
};
} }
} }
} };
};
ace.Editor.prototype.clearSelection = function() { ace.Editor.prototype.clearSelection = function() {
this.selectionLead = null; this.selectionLead = null;
this.selectionAnchor = null; this.selectionAnchor = null;
@ -596,23 +602,23 @@ ace.Editor.prototype.clearSelection = function() {
this.renderer.removeMarker(this.selection); this.renderer.removeMarker(this.selection);
this.selection = null; this.selection = null;
} }
}; };
ace.Editor.prototype.selectAll = function() { ace.Editor.prototype.selectAll = function() {
var lastRow = this.doc.getLength() - 1; var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length); this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
this._moveSelection(function() { this._moveSelection(function() {
this.moveCursorTo(0, 0); this.moveCursorTo(0, 0);
}); });
}; };
ace.Editor.prototype._moveSelection = function(mover) { ace.Editor.prototype._moveSelection = function(mover) {
if (!this.selectionAnchor) { if (!this.selectionAnchor) {
this.selectionAnchor = { this.selectionAnchor = {
row : this.cursor.row, row : this.cursor.row,
column : this.cursor.column column : this.cursor.column
} };
} }
mover.call(this); mover.call(this);
@ -620,7 +626,7 @@ ace.Editor.prototype._moveSelection = function(mover) {
this.selectionLead = { this.selectionLead = {
row : this.cursor.row, row : this.cursor.row,
column : this.cursor.column column : this.cursor.column
} };
if (this.selection) { if (this.selection) {
this.renderer.removeMarker(this.selection); this.renderer.removeMarker(this.selection);
@ -628,33 +634,33 @@ ace.Editor.prototype._moveSelection = function(mover) {
this.selection = this.renderer.addMarker(this.getSelectionRange(), this.selection = this.renderer.addMarker(this.getSelectionRange(),
"selection"); "selection");
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
}; };
ace.Editor.prototype.selectUp = function() { ace.Editor.prototype.selectUp = function() {
this._moveSelection(this.moveCursorUp); this._moveSelection(this.moveCursorUp);
}; };
ace.Editor.prototype.selectDown = function() { ace.Editor.prototype.selectDown = function() {
this._moveSelection(this.moveCursorDown); this._moveSelection(this.moveCursorDown);
}; };
ace.Editor.prototype.selectRight = function() { ace.Editor.prototype.selectRight = function() {
this._moveSelection(this.moveCursorRight); this._moveSelection(this.moveCursorRight);
}; };
ace.Editor.prototype.selectLeft = function() { ace.Editor.prototype.selectLeft = function() {
this._moveSelection(this.moveCursorLeft); this._moveSelection(this.moveCursorLeft);
}; };
ace.Editor.prototype.selectLineStart = function() { ace.Editor.prototype.selectLineStart = function() {
this._moveSelection(this.moveCursorLineStart); this._moveSelection(this.moveCursorLineStart);
}; };
ace.Editor.prototype.selectLineEnd = function() { ace.Editor.prototype.selectLineEnd = function() {
this._moveSelection(this.moveCursorLineEnd); this._moveSelection(this.moveCursorLineEnd);
}; };
ace.Editor.prototype.selectPageDown = function() { ace.Editor.prototype.selectPageDown = function() {
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow(); var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
var row = this.getPageDownRow() + Math.round(visibleRows / 2); var row = this.getPageDownRow() + Math.round(visibleRows / 2);
@ -663,9 +669,9 @@ ace.Editor.prototype.selectPageDown = function() {
this._moveSelection(function() { this._moveSelection(function() {
this.moveCursorTo(row, this.cursor.column); this.moveCursorTo(row, this.cursor.column);
}); });
}; };
ace.Editor.prototype.selectPageUp = function() { ace.Editor.prototype.selectPageUp = function() {
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow(); var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
var row = this.getPageUpRow() + Math.round(visibleRows / 2); var row = this.getPageUpRow() + Math.round(visibleRows / 2);
@ -674,13 +680,21 @@ ace.Editor.prototype.selectPageUp = function() {
this._moveSelection(function() { this._moveSelection(function() {
this.moveCursorTo(row, this.cursor.column); this.moveCursorTo(row, this.cursor.column);
}); });
}; };
ace.Editor.prototype.selectCurrentLine = function() { ace.Editor.prototype.selectFileEnd = function() {
this._moveSelection(this.moveCursorFileEnd);
};
ace.Editor.prototype.selectFileStart = function() {
this._moveSelection(this.moveCursorFileStart);
};
ace.Editor.prototype.selectCurrentLine = function() {
this.setSelectionAnchor(this.cursor.row, 0); this.setSelectionAnchor(this.cursor.row, 0);
this._moveSelection(function() { this._moveSelection(function() {
this.moveCursorTo(this.cursor.row + 1, 0); this.moveCursorTo(this.cursor.row + 1, 0);
}); });
} };
})(); })();

View file

@ -5,7 +5,7 @@ ace.GutterLayer = function(parentEl) {
this.element = document.createElement("div"); this.element = document.createElement("div");
this.element.className = "layer gutter-layer"; this.element.className = "layer gutter-layer";
parentEl.appendChild(this.element); parentEl.appendChild(this.element);
} };
ace.GutterLayer.prototype.update = function(config) { ace.GutterLayer.prototype.update = function(config) {
var html = []; var html = [];

View file

@ -3,9 +3,9 @@ if (!window.ace)
(function() { (function() {
ace.JavaScript = {}; ace.JavaScript = {};
var keywords = { var keywords = {
"break" : 1, "break" : 1,
"case" : 1, "case" : 1,
"catch" : 1, "catch" : 1,
@ -29,12 +29,12 @@ var keywords = {
"var" : 1, "var" : 1,
"while" : 1, "while" : 1,
"with" : 1 "with" : 1
}; };
// regexp must not have capturing parentheses // regexp must not have capturing parentheses
// regexps are ordered -> the first match is used // regexps are ordered -> the first match is used
ace.JavaScript.RULES = { ace.JavaScript.RULES = {
start : [ { start : [ {
token : "comment", token : "comment",
regex : "\\/\\/.*$" regex : "\\/\\/.*$"
@ -71,7 +71,7 @@ ace.JavaScript.RULES = {
return "keyword"; return "keyword";
} }
else { else {
return "identifier" return "identifier";
} }
}, },
regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b" regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
@ -109,6 +109,6 @@ ace.JavaScript.RULES = {
token : "string", token : "string",
regex : '.+' regex : '.+'
} ] } ]
}; };
})(); })();

View file

@ -8,7 +8,7 @@ ace.MarkerLayer = function(parentEl) {
this.markers = {}; this.markers = {};
this._markerId = 1; this._markerId = 1;
} };
ace.MarkerLayer.prototype.addMarker = function(range, clazz) { ace.MarkerLayer.prototype.addMarker = function(range, clazz) {
var id = this._markerId++; var id = this._markerId++;

View file

@ -6,10 +6,10 @@ ace.TextDocument = function(text) {
this.modified = true; this.modified = true;
this.listeners = []; this.listeners = [];
} };
ace.TextDocument.prototype._split = function(text) { ace.TextDocument.prototype._split = function(text) {
return text.split(/[\n\r]/) return text.split(/[\n\r]/);
}; };
ace.TextDocument.prototype.addChangeListener = function(listener) { ace.TextDocument.prototype.addChangeListener = function(listener) {
@ -67,37 +67,6 @@ ace.TextDocument.prototype.keywords = {
"with" : 1 "with" : 1
}; };
ace.TextDocument.prototype.getLineTokens = function(row) {
var tokens = [];
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
re.lastIndex = 0;
var match;
var line = this.getLine(row);
while (match = re.exec(line)) {
var token = {
type : "text",
value : match[0]
}
if (match[2] || match[3]) {
token.type = "string";
}
else if (match[5] && this.keywords[match[5]]) {
token.type = "keyword";
}
else if (match[6]) {
token.type = "comment";
}
tokens.push(token);
}
;
return tokens;
};
ace.TextDocument.prototype.getLength = function() { ace.TextDocument.prototype.getLength = function() {
return this.lines.length; return this.lines.length;
}; };
@ -148,7 +117,7 @@ ace.TextDocument.prototype._insert = function(position, text) {
return { return {
row : position.row, row : position.row,
column : position.column + text.length column : position.column + text.length
} };
} }
else { else {
var line = this.lines[position.row] || ""; var line = this.lines[position.row] || "";
@ -159,7 +128,7 @@ ace.TextDocument.prototype._insert = function(position, text) {
+ line.substring(position.column); + line.substring(position.column);
if (newLines.length > 2) { if (newLines.length > 2) {
var args = [ position.row + 1, 0 ] var args = [ position.row + 1, 0 ];
args.push.apply(args, newLines.slice(1, -1)); args.push.apply(args, newLines.slice(1, -1));
this.lines.splice.apply(this.lines, args); this.lines.splice.apply(this.lines, args);
} }
@ -209,4 +178,4 @@ ace.TextDocument.prototype.replace = function(range, text) {
: undefined); : undefined);
return end; return end;
} };

View file

@ -19,8 +19,8 @@ ace.TextInput = function(parentNode, host) {
host.onTextInput(text.value); host.onTextInput(text.value);
text.value = ""; text.value = "";
} }
}, 0) }, 0);
} };
var onCompositionStart = function(e) { var onCompositionStart = function(e) {
inCompostion = true; inCompostion = true;
@ -31,28 +31,28 @@ ace.TextInput = function(parentNode, host) {
host.onCompositionStart(); host.onCompositionStart();
setTimeout(onCompositionUpdate, 0); setTimeout(onCompositionUpdate, 0);
} };
var onCompositionUpdate = function() { var onCompositionUpdate = function() {
host.onCompositionUpdate(text.value); host.onCompositionUpdate(text.value);
} };
var onCompositionEnd = function() { var onCompositionEnd = function() {
inCompostion = false; inCompostion = false;
host.onCompositionEnd(); host.onCompositionEnd();
onTextInput(); onTextInput();
} };
var onCopy = function() { var onCopy = function() {
text.value = host.getCopyText(); text.value = host.getCopyText();
text.select(); text.select();
} };
var onCut = function() { var onCut = function() {
text.value = host.getCopyText(); text.value = host.getCopyText();
host.onCut(); host.onCut();
text.select(); text.select();
} };
ace.addListener(text, "keypress", onTextInput, false); ace.addListener(text, "keypress", onTextInput, false);
ace.addListener(text, "textInput", onTextInput, false); ace.addListener(text, "textInput", onTextInput, false);
@ -77,9 +77,9 @@ ace.TextInput = function(parentNode, host) {
this.focus = function() { this.focus = function() {
text.focus(); text.focus();
} };
this.blur = function() { this.blur = function() {
this.blur(); this.blur();
} };
}; };

View file

@ -7,7 +7,7 @@ ace.TextLayer = function(parentEl) {
parentEl.appendChild(this.element); parentEl.appendChild(this.element);
this._measureSizes(); this._measureSizes();
} };
ace.TextLayer.prototype.setTokenizer = function(tokenizer) { ace.TextLayer.prototype.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer; this.tokenizer = tokenizer;

View file

@ -33,9 +33,9 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
var token = { var token = {
type : "text", type : "text",
value : match[0] value : match[0]
} };
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error") } if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
lastIndex = re.lastIndex; lastIndex = re.lastIndex;
// console.log(match); // console.log(match);
@ -71,5 +71,5 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
return { return {
tokens : tokens, tokens : tokens,
state : currentState state : currentState
} };
}; };

View file

@ -32,7 +32,7 @@ ace.VirtualRenderer = function(container) {
row : 0, row : 0,
column : 0 column : 0
}; };
} };
ace.VirtualRenderer.prototype.setDocument = function(doc) { ace.VirtualRenderer.prototype.setDocument = function(doc) {
this.lines = doc.lines; this.lines = doc.lines;
@ -63,7 +63,7 @@ ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
// if the last row is unknow -> redraw everything // if the last row is unknow -> redraw everything
if (lastRow === undefined) { if (lastRow === undefined) {
this.draw() this.draw();
return; return;
} }
@ -108,7 +108,7 @@ ace.VirtualRenderer.prototype.draw = function() {
this.gutterLayer.element.style.marginTop = (-offset) + "px"; this.gutterLayer.element.style.marginTop = (-offset) + "px";
this.gutterLayer.element.style.height = minHeight + "px"; this.gutterLayer.element.style.height = minHeight + "px";
this.gutterLayer.update(layerConfig); this.gutterLayer.update(layerConfig);
} };
ace.VirtualRenderer.prototype.addMarker = function(range, clazz) { ace.VirtualRenderer.prototype.addMarker = function(range, clazz) {
return this.markerLayer.addMarker(range, clazz); return this.markerLayer.addMarker(range, clazz);
@ -134,7 +134,7 @@ ace.VirtualRenderer.prototype.showCursor = function() {
ace.VirtualRenderer.prototype.scrollCursorIntoView = function() { ace.VirtualRenderer.prototype.scrollCursorIntoView = function() {
var pos = this.cursorLayer.getPixelPosition(); var pos = this.cursorLayer.getPixelPosition();
var left = pos.left var left = pos.left;
var top = pos.top; var top = pos.top;
if (this.getScrollTop() > top) { if (this.getScrollTop() > top) {
@ -163,7 +163,7 @@ ace.VirtualRenderer.prototype.getScrollTop = function() {
ace.VirtualRenderer.prototype.scrollToRow = function(row) { ace.VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToY(row * this.lineHeight); this.scrollToY(row * this.lineHeight);
} };
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) { ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) {
var maxHeight = this.lines.length * this.lineHeight var maxHeight = this.lines.length * this.lineHeight
@ -187,7 +187,7 @@ ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
return { return {
row : row, row : row,
column : col column : col
} };
}; };
ace.VirtualRenderer.prototype.visualizeFocus = function() { ace.VirtualRenderer.prototype.visualizeFocus = function() {

View file

@ -3,85 +3,85 @@ if (!window.ace)
(function() { (function() {
ace.addListener = function(elem, type, callback) { ace.addListener = function(elem, type, callback) {
if (elem.addEventListener) { return elem.addEventListener(type, if (elem.addEventListener) { return elem.addEventListener(type,
callback, callback,
false); } false); }
if (elem.attachEvent) { if (elem.attachEvent) {
var wrapper = function() { var wrapper = function() {
callback(window.event); callback(window.event);
} };
callback.$$wrapper = wrapper; callback.$$wrapper = wrapper;
elem.attachEvent("on" + type, wrapper); elem.attachEvent("on" + type, wrapper);
} }
} };
ace.removeListener = function(elem, type, callback) { ace.removeListener = function(elem, type, callback) {
if (elem.removeEventListener) { return elem if (elem.removeEventListener) { return elem
.removeEventListener(type, callback, false); } .removeEventListener(type, callback, false); }
if (elem.detachEvent) { if (elem.detachEvent) {
elem.detachEvent("on" + type, callback.$$wrapper || callback); elem.detachEvent("on" + type, callback.$$wrapper || callback);
} }
} };
ace.setText = function(elem, text) { ace.setText = function(elem, text) {
if (elem.innerText !== undefined) { if (elem.innerText !== undefined) {
elem.innerText = text; elem.innerText = text;
} }
if (elem.textContent !== undefined) { if (elem.textContent !== undefined) {
elem.textContent = text; elem.textContent = text;
} }
} };
ace.stopEvent = function(e) { ace.stopEvent = function(e) {
ace.stopPropagation(e); ace.stopPropagation(e);
ace.preventDefault(e); ace.preventDefault(e);
return false; return false;
} };
ace.stopPropagation = function(e) { ace.stopPropagation = function(e) {
if (e.stopPropagation) if (e.stopPropagation)
e.stopPropagation(); e.stopPropagation();
else else
e.cancelBubble = true; e.cancelBubble = true;
} };
ace.preventDefault = function(e) { ace.preventDefault = function(e) {
if (e.preventDefault) if (e.preventDefault)
e.preventDefault(); e.preventDefault();
else else
e.returnValue = false; e.returnValue = false;
} };
ace.inherits = function(ctor, superCtor) { ace.inherits = function(ctor, superCtor) {
var tempCtor = function() { var tempCtor = function() {
}; };
tempCtor.prototype = superCtor.prototype; tempCtor.prototype = superCtor.prototype;
ctor.super_ = superCtor.prototype; ctor.super_ = superCtor.prototype;
ctor.prototype = new tempCtor(); ctor.prototype = new tempCtor();
ctor.prototype.constructor = ctor; ctor.prototype.constructor = ctor;
}; };
ace.getInnerWidth = function(element) { ace.getInnerWidth = function(element) {
return (parseInt(ace.computedStyle(element, "paddingLeft")) return (parseInt(ace.computedStyle(element, "paddingLeft"))
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth); + parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
}; };
ace.getInnerHeight = function(element) { ace.getInnerHeight = function(element) {
return (parseInt(ace.computedStyle(element, "paddingTop")) return (parseInt(ace.computedStyle(element, "paddingTop"))
+ parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight); + parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight);
}; };
ace.computedStyle = function(element, style) { ace.computedStyle = function(element, style) {
if (window.getComputedStyle) { if (window.getComputedStyle) {
return (window.getComputedStyle(element, null))[style]; return (window.getComputedStyle(element, null))[style];
} }
else { else {
return element.currentStyle[style]; return element.currentStyle[style];
} }
} };
ace.scrollbarHeight = function() { ace.scrollbarHeight = function() {
var el = document.createElement("div"); var el = document.createElement("div");
var style = el.style; var style = el.style;
@ -95,15 +95,15 @@ ace.scrollbarHeight = function() {
document.body.removeChild(el); document.body.removeChild(el);
return height; return height;
} };
ace.bind = function(fcn, context) { ace.bind = function(fcn, context) {
return function() { return function() {
return fcn.apply(context, arguments); return fcn.apply(context, arguments);
} };
} };
ace.capture = function(el, eventHandler, releaseCaptureHandler) { ace.capture = function(el, eventHandler, releaseCaptureHandler) {
function onMouseMove(e) { function onMouseMove(e) {
eventHandler(e); eventHandler(e);
e.stopPropagation(); e.stopPropagation();
@ -121,24 +121,24 @@ ace.capture = function(el, eventHandler, releaseCaptureHandler) {
document.addEventListener("mousemove", onMouseMove, true); document.addEventListener("mousemove", onMouseMove, true);
document.addEventListener("mouseup", onMouseUp, true); document.addEventListener("mouseup", onMouseUp, true);
} };
ace.addMouseWheelListener = function(el, callback) { ace.addMouseWheelListener = function(el, callback) {
var listener = function(e) { var listener = function(e) {
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
: -(e.detail || 0) / 3; : -(e.detail || 0) / 3;
callback(e); callback(e);
} };
ace.addListener(el, "DOMMouseScroll", listener); ace.addListener(el, "DOMMouseScroll", listener);
ace.addListener(el, "mousewheel", listener); ace.addListener(el, "mousewheel", listener);
}; };
ace.autoremoveListener = function(el, type, callback, timeout) { ace.autoremoveListener = function(el, type, callback, timeout) {
var listener = function(e) { var listener = function(e) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
remove(); remove();
callback(e); callback(e);
} };
var remove = function() { var remove = function() {
ace.removeListener(el, type, listener); ace.removeListener(el, type, listener);
@ -146,14 +146,14 @@ ace.autoremoveListener = function(el, type, callback, timeout) {
ace.addListener(el, type, listener); ace.addListener(el, type, listener);
var timeoutId = setTimeout(remove, timeout); var timeoutId = setTimeout(remove, timeout);
} };
ace.addTripleClickListener = function(el, callback) { ace.addTripleClickListener = function(el, callback) {
ace.addListener(el, "mousedown", function() { ace.addListener(el, "mousedown", function() {
ace.autoremoveListener(el, "mousedown", function() { ace.autoremoveListener(el, "mousedown", function() {
ace.autoremoveListener(el, "mousedown", callback, 300); ace.autoremoveListener(el, "mousedown", callback, 300);
}, 300); }, 300);
}); });
} };
})(); })();

View file

@ -1,16 +1,16 @@
MockRenderer = function() { MockRenderer = function() {
this.container = document.createElement("div"); this.container = document.createElement("div");
this.cursor = { this.cursor = {
row: 0, row : 0,
column: 0 column : 0
} };
this.visibleRowCount = 20; this.visibleRowCount = 20;
this.layerConfig = { this.layerConfig = {
firstVisibleRow: 0, firstVisibleRow : 0,
lastVisibleRow: this.visibleRowCount, lastVisibleRow : this.visibleRowCount
} };
}; };
@ -41,18 +41,22 @@ MockRenderer.prototype.updateCursor = function(position) {
MockRenderer.prototype.scrollCursorIntoView = function() { MockRenderer.prototype.scrollCursorIntoView = function() {
if (this.cursor.row < this.layerConfig.firstVisibleRow) { if (this.cursor.row < this.layerConfig.firstVisibleRow) {
this.scrollToRow(this.cursor.row); this.scrollToRow(this.cursor.row);
} else if (this.cursor.row > this.layerConfig.lastVisibleRow) { }
else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
this.scrollToRow(this.cursor.row); this.scrollToRow(this.cursor.row);
} }
}; };
MockRenderer.prototype.scrollToRow = function(row) { MockRenderer.prototype.scrollToRow = function(row) {
var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0, row)); var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0,
row));
this.layerConfig.firstVisibleRow = row; this.layerConfig.firstVisibleRow = row;
this.layerConfig.lastVisibleRow = row + this.visibleRowCount; this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
} };
MockRenderer.prototype.draw = function() { MockRenderer.prototype.draw = function() {
}; };
MockRenderer.prototype.addMarker = function() {
};

View file

@ -47,5 +47,37 @@ var NavigationTest = TestCase("NavigationTest", {
editor.navigateFileStart(); editor.navigateFileStart();
assertEquals(0, editor.getFirstVisibleRow()); assertEquals(0, editor.getFirstVisibleRow());
},
"test: move selection lead to end of file" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.moveCursorTo(100, 5);
editor.selectFileEnd();
var selection = editor.getSelectionRange();
assertEquals(100, selection.start.row);
assertEquals(5, selection.start.column);
assertEquals(199, selection.end.row);
assertEquals(10, selection.end.column);
},
"test: move selection lead to start of file" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.moveCursorTo(100, 5);
editor.selectFileStart();
var selection = editor.getSelectionRange();
assertEquals(0, selection.start.row);
assertEquals(0, selection.start.column);
assertEquals(100, selection.end.row);
assertEquals(5, selection.end.column);
} }
}); });