adapt better to ajax.org coding styles

This commit is contained in:
Fabian Jakobs 2010-04-12 12:49:00 +02:00
commit 8fe20516d4
13 changed files with 1556 additions and 1645 deletions

View file

@ -1,22 +1,21 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
{
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete) {
this.running = false;
this.textLines = [];
this.lines = [];
this.currentLine = 0;
this.tokenizer = tokenizer;
this.onUpdate = onUpdate || function(firstLine, lastLine) {};
this.onComplete = onComplete || function() {};
this.onUpdate = onUpdate || function(firstLine, lastLine) {
};
this.onComplete = onComplete || function() {
};
var self = this;
this._worker = function()
{
if (!self.running) {
return;
}
this._worker = function() {
if (!self.running) { return; }
var workerStart = new Date();
var startLine = self.currentLine;
@ -24,17 +23,17 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
var processedLines = 0;
while (self.currentLine < textLines.length)
{
while (self.currentLine < textLines.length) {
var line = textLines[self.currentLine];
var state = self.currentLine == 0 ? "start" : self.lines[self.currentLine-1].state;
self.lines[self.currentLine] = self.tokenizer.getLineTokens(line, state);
var state = self.currentLine == 0 ? "start"
: self.lines[self.currentLine - 1].state;
self.lines[self.currentLine] = self.tokenizer.getLineTokens(line,
state);
// only check every 30 lines
processedLines += 1;
if ((processedLines % 30 == 0) && (new Date()-workerStart) > 20)
{
if ((processedLines % 30 == 0) && (new Date() - workerStart) > 20) {
self.onUpdate(startLine, self.currentLine);
return setTimeout(self._worker, 10);
}
@ -44,26 +43,24 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
self.running = false;
self.onUpdate(startLine, textLines.length-1);
self.onUpdate(startLine, textLines.length - 1);
self.onComplete();
}
};
ace.BackgroundTokenizer.prototype.setLines = function(textLines)
{
ace.BackgroundTokenizer.prototype.setLines = function(textLines) {
this.textLines = textLines;
this.lines = [];
this.stop();
};
ace.BackgroundTokenizer.prototype.start = function(startRow)
{
this.currentLine = Math.min(startRow || 0, this.currentLine, this.textLines.length);
ace.BackgroundTokenizer.prototype.start = function(startRow) {
this.currentLine = Math.min(startRow || 0, this.currentLine,
this.textLines.length);
this.lines.splice(startRow, this.lines.length);
if (!this.running)
{
if (!this.running) {
this.running = true;
setTimeout(this._worker, 50);
}
@ -73,14 +70,14 @@ ace.BackgroundTokenizer.prototype.stop = function() {
this.running = false;
};
ace.BackgroundTokenizer.prototype.getTokens = function(row)
{
ace.BackgroundTokenizer.prototype.getTokens = function(row) {
if (this.lines[row]) {
return this.lines[row].tokens;
} else {
}
else {
var state = "start";
if (row > 0 && this.lines[row-1]) {
state = this.lines[row-1].state;
if (row > 0 && this.lines[row - 1]) {
state = this.lines[row - 1].state;
}
return this.tokenizer.getLineTokens(this.textLines[row] || "", state).tokens;
}

View file

@ -1,7 +1,7 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.CursorLayer = function(parentEl)
{
ace.CursorLayer = function(parentEl) {
this.element = document.createElement("div");
this.element.className = "layer cursor-layer";
parentEl.appendChild(this.element);
@ -12,16 +12,14 @@ ace.CursorLayer = function(parentEl)
this.isVisible = false;
}
ace.CursorLayer.prototype.setCursor = function(position)
{
ace.CursorLayer.prototype.setCursor = function(position) {
this.position = {
row: position.row,
column: position.column
row : position.row,
column : position.column
};
};
ace.CursorLayer.prototype.hideCursor = function()
{
ace.CursorLayer.prototype.hideCursor = function() {
this.isVisible = false;
if (this.cursor.parentNode) {
this.cursor.parentNode.removeChild(this.cursor);
@ -29,8 +27,7 @@ ace.CursorLayer.prototype.hideCursor = function()
clearInterval(this.blinkId);
};
ace.CursorLayer.prototype.showCursor = function()
{
ace.CursorLayer.prototype.showCursor = function() {
this.isVisible = true;
this.element.appendChild(this.cursor);
@ -46,23 +43,27 @@ ace.CursorLayer.prototype.showCursor = function()
};
ace.CursorLayer.prototype.getPixelPosition = function() {
return this.pixelPos || {left: 0, top:0};
return this.pixelPos || {
left : 0,
top : 0
};
}
ace.CursorLayer.prototype.update = function(config)
{
if (!this.position) return;
ace.CursorLayer.prototype.update = function(config) {
if (!this.position)
return;
var cursorLeft = Math.round(this.position.column * config.characterWidth);
var cursorTop = this.position.row * config.lineHeight;
this.pixelPos = {
left: cursorLeft,
top: cursorTop
left : cursorLeft,
top : cursorTop
};
this.cursor.style.left = cursorLeft + "px";
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight)) + "px";
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight))
+ "px";
this.cursor.style.height = config.lineHeight + "px";
if (this.isVisible) {

View file

@ -1,33 +1,30 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
(function() {
var keys = {
UP: 38,
RIGHT: 39,
DOWN: 40,
LEFT: 37,
PAGEUP: 33,
PAGEDOWN: 34,
POS1: 36,
END: 35,
DELETE: 46,
BACKSPACE: 8,
TAB: 9,
A: 65
UP : 38,
RIGHT : 39,
DOWN : 40,
LEFT : 37,
PAGEUP : 33,
PAGEDOWN : 34,
POS1 : 36,
END : 35,
DELETE : 46,
BACKSPACE : 8,
TAB : 9,
A : 65
}
var KeyBinding = function(element, host)
{
ace.addListener(element, "keydown", function(e)
{
var KeyBinding = function(element, host) {
ace.addListener(element, "keydown", function(e) {
var key = e.keyCode;
switch (key)
{
switch (key) {
case keys.A:
if (e.metaKey)
{
if (e.metaKey) {
host.selectAll();
return ace.stopEvent(e);
}
@ -36,9 +33,11 @@ var KeyBinding = function(element, host)
case keys.UP:
if (e.metaKey) {
host.navigateFileStart();
} if (e.shiftKey) {
}
if (e.shiftKey) {
host.selectUp();
} else {
}
else {
host.navigateUp();
}
return ace.stopEvent(e);
@ -46,9 +45,11 @@ var KeyBinding = function(element, host)
case keys.DOWN:
if (e.metaKey) {
host.navigateFileEnd();
} if (e.shiftKey) {
}
if (e.shiftKey) {
host.selectDown();
} else{
}
else {
host.navigateDown();
}
return ace.stopEvent(e);
@ -56,11 +57,14 @@ var KeyBinding = function(element, host)
case keys.LEFT:
if (e.metaKey && e.shiftKey) {
host.selectLineStart();
} else if (e.metaKey) {
}
else if (e.metaKey) {
host.navigateLineStart();
} else if (e.shiftKey) {
}
else if (e.shiftKey) {
host.selectLeft();
} else {
}
else {
host.navigateLeft();
}
return ace.stopEvent(e);
@ -68,11 +72,14 @@ var KeyBinding = function(element, host)
case keys.RIGHT:
if (e.metaKey && e.shiftKey) {
host.selectLineEnd();
} else if (e.metaKey) {
}
else if (e.metaKey) {
host.navigateLineEnd();
} else if (e.shiftKey) {
}
else if (e.shiftKey) {
host.selectRight();
} else {
}
else {
host.navigateRight();
}
return ace.stopEvent(e);
@ -80,7 +87,8 @@ var KeyBinding = function(element, host)
case keys.PAGEDOWN:
if (e.shiftKey) {
host.selectPageDown();
} else {
}
else {
host.scrollPageDown();
}
return ace.stopEvent(e);
@ -88,7 +96,8 @@ var KeyBinding = function(element, host)
case keys.PAGEUP:
if (e.shiftKey) {
host.selectPageUp();
} else {
}
else {
host.scrollPageUp();
}
return ace.stopEvent(e);
@ -96,7 +105,8 @@ var KeyBinding = function(element, host)
case keys.POS1:
if (e.shiftKey) {
host.selectLineStart();
} else {
}
else {
host.navigateLineStart();
}
return ace.stopEvent(e);
@ -104,7 +114,8 @@ var KeyBinding = function(element, host)
case keys.END:
if (e.shiftKey) {
host.selectLineEnd();
} else {
}
else {
host.navigateLineEnd();
}
return ace.stopEvent(e);
@ -124,34 +135,34 @@ var KeyBinding = function(element, host)
});
};
ace.Editor = function(doc, renderer)
{
ace.Editor = function(doc, renderer) {
var container = renderer.getContainerElement();
this.renderer = renderer;
this.textInput = new ace.TextInput(container, this);
new KeyBinding(container, this);
ace.addListener(container, "mousedown", ace.bind(this.onMouseDown, this));
ace.addListener(container, "dblclick", ace.bind(this.onMouseDoubleClick, this));
ace.addListener(container, "mousedown", ace
.bind(this.onMouseDown, this));
ace.addListener(container, "dblclick", ace
.bind(this.onMouseDoubleClick, this));
ace.addMouseWheelListener(container, ace.bind(this.onMouseWheel, this));
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine, this));
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine,
this));
this.doc = doc;
doc.addChangeListener(ace.bind(this.onDocumentChange, this));
renderer.setDocument(doc);
this.tokenizer = new ace.BackgroundTokenizer(
new ace.Tokenizer(ace.XML.RULES),
ace.bind(this.onTokenizerUpdate, this)
);
this.tokenizer = new ace.BackgroundTokenizer(new ace.Tokenizer(
ace.XML.RULES), ace.bind(this.onTokenizerUpdate, this));
this.tokenizer.setLines(doc.lines);
renderer.setTokenizer(this.tokenizer);
this.cursor = {
row: 0,
column: 0
row : 0,
column : 0
};
this.selectionAnchor = null;
@ -179,8 +190,7 @@ ace.Editor.prototype.onBlur = function() {
this.renderer.visualizeBlur();
};
ace.Editor.prototype.onDocumentChange = function(startRow, endRow)
{
ace.Editor.prototype.onDocumentChange = function(startRow, endRow) {
this.tokenizer.start(startRow);
this.renderer.updateLines(startRow, endRow);
};
@ -189,8 +199,7 @@ ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) {
this.renderer.updateLines(startRow, endRow);
};
ace.Editor.prototype.onMouseDown = function(e)
{
ace.Editor.prototype.onMouseDown = function(e) {
this.textInput.focus();
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
@ -210,11 +219,12 @@ ace.Editor.prototype.onMouseDown = function(e)
clearInterval(timerId);
};
var onSelectionInterval = function()
{
if (mousePageX === undefined || mousePageY === undefined) return;
var onSelectionInterval = function() {
if (mousePageX === undefined || mousePageY === undefined)
return;
selectionLead = _self.renderer.screenToTextCoordinates(mousePageX, mousePageY);
selectionLead = _self.renderer.screenToTextCoordinates(mousePageX,
mousePageY);
_self._moveSelection(function() {
_self.moveCursorTo(selectionLead.row, selectionLead.column);
@ -223,13 +233,12 @@ ace.Editor.prototype.onMouseDown = function(e)
};
ace.capture(this.container, onMouseSelection, onMouseSelectionEnd);
var timerId = setInterval(onSelectionInterval, 20 );
var timerId = setInterval(onSelectionInterval, 20);
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 column = this.cursor.column;
@ -238,7 +247,7 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
var inToken = false;
if (column > 0) {
inToken = !!line.charAt(column-1).match(tokenRe);
inToken = !!line.charAt(column - 1).match(tokenRe);
}
if (!inToken) {
@ -248,11 +257,11 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
var re = inToken ? tokenRe : nonTokenRe;
var start = column;
if (start > 0)
{
if (start > 0) {
do {
start--;
} while (start >= 0 && line.charAt(start).match(re))
}
while (start >= 0 && line.charAt(start).match(re))
start++;
}
@ -267,103 +276,96 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
});
};
ace.Editor.prototype.onMouseWheel = function(e)
{
ace.Editor.prototype.onMouseWheel = function(e) {
var delta = e.wheel;
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
return ace.preventDefault(e);
};
ace.Editor.prototype.getCopyText = function()
{
ace.Editor.prototype.getCopyText = function() {
if (this.hasSelection()) {
return this.doc.getTextRange(this.getSelectionRange());
} else {
}
else {
return "";
}
};
ace.Editor.prototype.onCut = function()
{
if (this.hasSelection())
{
ace.Editor.prototype.onCut = function() {
if (this.hasSelection()) {
this.cursor = this.doc.remove(this.getSelectionRange());
this.clearSelection();
this.renderer.updateCursor(this.cursor);
}
};
ace.Editor.prototype.onTextInput = function(text)
{
if (this.hasSelection())
{
ace.Editor.prototype.onTextInput = function(text) {
if (this.hasSelection()) {
this.cursor = this.doc.replace(this.getSelectionRange(), text);
this.clearSelection();
} else {
}
else {
this.cursor = this.doc.insert(this.cursor, text);
}
this.renderer.updateCursor(this.cursor);
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.removeRight = function()
{
if (this.hasSelection())
{
ace.Editor.prototype.removeRight = function() {
if (this.hasSelection()) {
this.cursor = this.doc.remove(this.getSelectionRange());
this.renderer.updateCursor(this.cursor);
this.clearSelection();
}
else
{
else {
var rangeEnd = {
row: this.cursor.row,
column: this.cursor.column + 1
row : this.cursor.row,
column : this.cursor.column + 1
}
if (rangeEnd.column > this.doc.getLine(this.cursor.row).length) {
rangeEnd.row += 1;
rangeEnd.column = 0;
}
this.doc.remove({start: this.cursor, end: renageEnd});
this.doc.remove( {
start : this.cursor,
end : renageEnd
});
}
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.removeLeft = function()
{
if (this.hasSelection())
{
ace.Editor.prototype.removeLeft = function() {
if (this.hasSelection()) {
this.cursor = this.doc.remove(this.getSelectionRange());
this.clearSelection();
}
else
{
if (this.cursor.row == 0 && this.cursor.column == 0) {
return;
}
else {
if (this.cursor.row == 0 && this.cursor.column == 0) { return; }
var rangeStart = {
row: this.cursor.row,
column: this.cursor.column + -1
row : this.cursor.row,
column : this.cursor.column + -1
}
if (rangeStart.column < 0)
{
if (rangeStart.column < 0) {
rangeStart.row -= 1;
rangeStart.column = this.doc.getLine(this.cursor.row-1).length;
rangeStart.column = this.doc
.getLine(this.cursor.row - 1).length;
}
this.cursor = this.doc.remove({start: rangeStart, end: this.cursor});
this.cursor = this.doc.remove( {
start : rangeStart,
end : this.cursor
});
}
this.renderer.updateCursor(this.cursor);
this.renderer.scrollCursorIntoView();
},
},
ace.Editor.prototype.onCompositionStart = function()
{
ace.Editor.prototype.onCompositionStart = function() {
this.renderer.showComposition(this.cursor);
this.onTextInput(" ");
};
};
ace.Editor.prototype.onCompositionUpdate = function(text) {
this.renderer.setCompositionText(text);
@ -386,12 +388,11 @@ ace.Editor.prototype.getPageDownRow = function() {
return this.renderer.getLastVisibleRow() - 1;
};
ace.Editor.prototype.getPageUpRow = function()
{
ace.Editor.prototype.getPageUpRow = function() {
var firstRow = this.renderer.getFirstVisibleRow();
var lastRow = this.renderer.getLastVisibleRow();
return firstRow - (lastRow-firstRow) + 1;
return firstRow - (lastRow - firstRow) + 1;
};
ace.Editor.prototype.scrollPageDown = function() {
@ -406,8 +407,7 @@ ace.Editor.prototype.scrollToRow = function(row) {
this.renderer.scrollToRow(row);
};
ace.Editor.prototype.navigateUp = function()
{
ace.Editor.prototype.navigateUp = function() {
this.clearSelection();
this.moveCursorUp();
this.renderer.scrollCursorIntoView();
@ -419,12 +419,12 @@ ace.Editor.prototype.navigateDown = function() {
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.navigateLeft = function()
{
ace.Editor.prototype.navigateLeft = function() {
if (this.hasSelection()) {
var selectionStart = this.getSelectionRange().start;
this.moveCursorTo(selectionStart.row, selectionStart.column);
} else {
}
else {
this.moveCursorLeft();
}
this.clearSelection();
@ -432,12 +432,12 @@ ace.Editor.prototype.navigateLeft = function()
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.navigateRight = function()
{
ace.Editor.prototype.navigateRight = function() {
if (this.hasSelection()) {
var selectionEnd = this.getSelectionRange().end;
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
} else {
}
else {
this.moveCursorRight();
}
this.clearSelection();
@ -445,29 +445,25 @@ ace.Editor.prototype.navigateRight = function()
this.renderer.scrollCursorIntoView();
},
ace.Editor.prototype.navigateLineStart = function()
{
ace.Editor.prototype.navigateLineStart = function() {
this.clearSelection();
this.moveCursorLineStart();
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.navigateLineEnd = function()
{
ace.Editor.prototype.navigateLineEnd = function() {
this.clearSelection();
this.moveCursorLineEnd();
this.renderer.scrollCursorIntoView();
};
ace.Editor.prototype.navigateFileEnd = function()
{
ace.Editor.prototype.navigateFileEnd = function() {
this.clearSelection();
this.moveCursorFileEnd();
this.renderer.scrollCursorIntoView();
},
ace.Editor.prototype.navigateFileStart = function()
{
ace.Editor.prototype.navigateFileStart = function() {
this.clearSelection();
this.moveCursorFileStart();
this.renderer.scrollCursorIntoView();
@ -481,24 +477,25 @@ ace.Editor.prototype.moveCursorDown = function() {
this.moveCursorBy(1, 0);
};
ace.Editor.prototype.moveCursorLeft = function()
{
ace.Editor.prototype.moveCursorLeft = function() {
if (this.cursor.column == 0) {
if (this.cursor.row > 0) {
this.moveCursorTo(this.cursor.row-1, this.doc.getLine(this.cursor.row-1).length);
this.moveCursorTo(this.cursor.row - 1, this.doc
.getLine(this.cursor.row - 1).length);
}
} else {
}
else {
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.row < this.doc.getLength()-1) {
this.moveCursorTo(this.cursor.row+1, 0);
if (this.cursor.row < this.doc.getLength() - 1) {
this.moveCursorTo(this.cursor.row + 1, 0);
}
} else {
}
else {
this.moveCursorBy(0, 1);
}
};
@ -508,7 +505,8 @@ ace.Editor.prototype.moveCursorLineStart = function() {
};
ace.Editor.prototype.moveCursorLineEnd = function() {
this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length);
this.moveCursorTo(this.cursor.row,
this.doc.getLine(this.cursor.row).length);
};
ace.Editor.prototype.moveCursorFileEnd = function() {
@ -522,29 +520,31 @@ ace.Editor.prototype.moveCursorFileStart = function() {
};
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()) {
this.cursor.row = this.doc.getLength()-1;
this.cursor.row = this.doc.getLength() - 1;
this.cursor.column = this.doc.getLine(this.cursor.row).length;
} else if (row < 0) {
}
else if (row < 0) {
this.cursor.row = 0;
this.cursor.column = 0;
} else {
}
else {
this.cursor.row = row;
this.cursor.column = Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column));
this.cursor.column = Math
.min(this.doc.getLine(this.cursor.row).length, Math
.max(0, column));
}
this.updateCursor();
};
ace.Editor.prototype.getCursorPosition = function()
{
ace.Editor.prototype.getCursorPosition = function() {
return {
row: this.cursor.row,
column: this.cursor.column
row : this.cursor.row,
column : this.cursor.column
}
};
@ -552,42 +552,43 @@ ace.Editor.prototype.hasSelection = function() {
return !!this.selectionLead;
};
ace.Editor.prototype.setSelectionAnchor = function(row, column)
{
ace.Editor.prototype.setSelectionAnchor = function(row, column) {
this.clearSelection();
this.selectionAnchor = {
row: Math.min(this.doc.getLength()-1, Math.max(0, row)),
column: Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column))
row : Math.min(this.doc.getLength() - 1, Math.max(0, row)),
column : Math.min(this.doc.getLine(this.cursor.row).length, Math
.max(0, column))
};
this.selectionLead = null;
};
ace.Editor.prototype.getSelectionRange = function()
{
ace.Editor.prototype.getSelectionRange = function() {
var anchor = this.selectionAnchor;
var lead = this.selectionLead;
if (!anchor) {
return null;
} else {
if (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column)) {
return {
start: lead,
end: anchor
}
} else {
else {
if (anchor.row > lead.row
|| (anchor.row == lead.row && anchor.column > lead.column)) {
return {
start: anchor,
end: lead
start : lead,
end : anchor
}
}
else {
return {
start : anchor,
end : lead
}
}
}
};
ace.Editor.prototype.clearSelection = function()
{
ace.Editor.prototype.clearSelection = function() {
this.selectionLead = null;
this.selectionAnchor = null;
@ -597,9 +598,8 @@ ace.Editor.prototype.clearSelection = function()
}
};
ace.Editor.prototype.selectAll = function()
{
var lastRow = this.doc.getLength()-1;
ace.Editor.prototype.selectAll = function() {
var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
this._moveSelection(function() {
@ -607,26 +607,26 @@ ace.Editor.prototype.selectAll = function()
});
};
ace.Editor.prototype._moveSelection = function(mover)
{
ace.Editor.prototype._moveSelection = function(mover) {
if (!this.selectionAnchor) {
this.selectionAnchor = {
row: this.cursor.row,
column: this.cursor.column
row : this.cursor.row,
column : this.cursor.column
}
}
mover.call(this);
this.selectionLead = {
row: this.cursor.row,
column: this.cursor.column
row : this.cursor.row,
column : this.cursor.column
}
if (this.selection) {
this.renderer.removeMarker(this.selection);
}
this.selection = this.renderer.addMarker(this.getSelectionRange(), "selection");
this.selection = this.renderer.addMarker(this.getSelectionRange(),
"selection");
this.renderer.scrollCursorIntoView();
};
@ -654,8 +654,7 @@ ace.Editor.prototype.selectLineEnd = function() {
this._moveSelection(this.moveCursorLineEnd);
};
ace.Editor.prototype.selectPageDown = function()
{
ace.Editor.prototype.selectPageDown = function() {
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
@ -666,8 +665,7 @@ ace.Editor.prototype.selectPageDown = function()
});
};
ace.Editor.prototype.selectPageUp = function()
{
ace.Editor.prototype.selectPageUp = function() {
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
@ -678,11 +676,10 @@ ace.Editor.prototype.selectPageUp = function()
});
};
ace.Editor.prototype.selectCurrentLine = function()
{
ace.Editor.prototype.selectCurrentLine = function() {
this.setSelectionAnchor(this.cursor.row, 0);
this._moveSelection(function() {
this.moveCursorTo(this.cursor.row+1, 0);
this.moveCursorTo(this.cursor.row + 1, 0);
});
}

View file

@ -1,22 +1,17 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.GutterLayer = function(parentEl)
{
ace.GutterLayer = function(parentEl) {
this.element = document.createElement("div");
this.element.className = "layer gutter-layer";
parentEl.appendChild(this.element);
}
ace.GutterLayer.prototype.update = function(config)
{
ace.GutterLayer.prototype.update = function(config) {
var html = [];
for (var i=config.firstRow; i<=config.lastRow; i++)
{
html.push(
"<div class='gutter-cell' style='height:" + config.lineHeight + "px;'>",
i,
"</div>"
);
for ( var i = config.firstRow; i <= config.lastRow; i++) {
html.push("<div class='gutter-cell' style='height:" + config.lineHeight
+ "px;'>", i, "</div>");
html.push("</div>");
}

View file

@ -1,4 +1,5 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
(function() {
@ -34,106 +35,80 @@ var keywords = {
// regexps are ordered -> the first match is used
ace.JavaScript.RULES = {
start :
[
{
token: "comment",
regex: "\\/\\/.*$"
},
{
token: "comment", // multi line comment in one line
regex: "\\/\\*.*?\\*\\/"
},
{
token: "comment", // multi line comment start
regex: "\\/\\*.*$",
next: "comment"
},
{
token: "string", // single line
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
},
{
token: "string", // multi line string start
regex: '["].*\\\\$',
next: "qqstring"
},
{
token: "string", // single line
regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
},
{
token: "string", // multi line string start
regex: "['].*\\\\$",
next: "qstring"
},
{
token: "number", // hex
regex: "0[xX][0-9a-fA-F]+\\b"
},
{
token: "number", // float
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
},
{
token: function(value)
{
start : [ {
token : "comment",
regex : "\\/\\/.*$"
}, {
token : "comment", // multi line comment in one line
regex : "\\/\\*.*?\\*\\/"
}, {
token : "comment", // multi line comment start
regex : "\\/\\*.*$",
next : "comment"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // multi line string start
regex : '["].*\\\\$',
next : "qqstring"
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "string", // multi line string start
regex : "['].*\\\\$",
next : "qstring"
}, {
token : "number", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
}, {
token : "number", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : function(value) {
if (keywords[value]) {
return "keyword";
} else {
}
else {
return "identifier"
}
},
regex: "[a-zA-Z_][a-zA-Z0-9_]*\\b"
},
{
token: function(value) {
//return parens[value];
regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
}, {
token : function(value) {
// return parens[value];
return "text";
},
regex: "[\\[\\]\\(\\)\\{\\}]"
},
{
token: "text",
regex: "\\s+"
}
],
"comment":
[
{
token: "comment", // closing comment
regex: ".*?\\*\\/",
next: "start"
},
{
token: "comment", // comment spanning whole line
regex: ".+"
}
],
"qqstring":
[
{
token: "string",
regex: '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
next: "start"
},
{
token: "string",
regex: '.+'
}
],
"qstring":
[
{
token: "string",
regex: "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
next: "start"
},
{
token: "string",
regex: '.+'
}
]
regex : "[\\[\\]\\(\\)\\{\\}]"
}, {
token : "text",
regex : "\\s+"
} ],
"comment" : [ {
token : "comment", // closing comment
regex : ".*?\\*\\/",
next : "start"
}, {
token : "comment", // comment spanning whole line
regex : ".+"
} ],
"qqstring" : [ {
token : "string",
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
next : "start"
}, {
token : "string",
regex : '.+'
} ],
"qstring" : [ {
token : "string",
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
next : "start"
}, {
token : "string",
regex : '.+'
} ]
};
})();

View file

@ -1,7 +1,7 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.MarkerLayer = function(parentEl)
{
ace.MarkerLayer = function(parentEl) {
this.element = document.createElement("div");
this.element.className = "layer marker-layer";
parentEl.appendChild(this.element);
@ -10,88 +10,96 @@ ace.MarkerLayer = function(parentEl)
this._markerId = 1;
}
ace.MarkerLayer.prototype.addMarker = function(range, clazz)
{
ace.MarkerLayer.prototype.addMarker = function(range, clazz) {
var id = this._markerId++;
this.markers[id] = {
range: range,
type: "line",
clazz: clazz
range : range,
type : "line",
clazz : clazz
};
this.update();
return id;
};
ace.MarkerLayer.prototype.removeMarker = function(markerId)
{
ace.MarkerLayer.prototype.removeMarker = function(markerId) {
var marker = this.markers[markerId];
if (marker) {
delete(this.markers[markerId]);
delete (this.markers[markerId]);
this.update();
}
};
ace.MarkerLayer.prototype.update = function(config)
{
ace.MarkerLayer.prototype.update = function(config) {
var config = config || this.config;
if (!config) return;
if (!config)
return;
this.config = config;
var html = [];
for (var key in this.markers)
{
for ( var key in this.markers) {
var marker = this.markers[key];
var range = marker.range;
if (range.start.row !== range.end.row)
{
if (range.start.row >= config.firstRow && range.start.row <= config.lastRow)
{
html.push(
"<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;",
"width:", Math.round(config.width - (range.start.column * config.characterWidth)), "px;",
"top:", (range.start.row-config.firstRow) * config.lineHeight, "px;",
"left:", Math.round(range.start.column * config.characterWidth), "px;'></div>"
);
if (range.start.row !== range.end.row) {
if (range.start.row >= config.firstRow
&& range.start.row <= config.lastRow) {
html
.push(
"<div class='",
marker.clazz,
"' style='",
"height:",
config.lineHeight,
"px;",
"width:",
Math
.round(config.width
- (range.start.column * config.characterWidth)),
"px;", "top:",
(range.start.row - config.firstRow)
* config.lineHeight, "px;", "left:", Math
.round(range.start.column
* config.characterWidth),
"px;'></div>");
}
if (range.end.row >= config.firstRow && range.end.row <= config.lastRow)
{
html.push(
"<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;",
"top:", (range.end.row-config.firstRow) * config.lineHeight, "px;",
"width:", Math.round(range.end.column * config.characterWidth), "px;'></div>"
);
};
if (range.end.row >= config.firstRow
&& range.end.row <= config.lastRow) {
html
.push("<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;", "top:",
(range.end.row - config.firstRow)
* config.lineHeight, "px;", "width:",
Math.round(range.end.column
* config.characterWidth), "px;'></div>");
}
;
for (var row=range.start.row+1; row < range.end.row; row++)
{
if (row >= config.firstRow && row <= config.lastRow)
{
html.push(
"<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;",
"width:", config.width, "px;",
"top:", (row-config.firstRow) * config.lineHeight, "px;'></div>"
);
for ( var row = range.start.row + 1; row < range.end.row; row++) {
if (row >= config.firstRow && row <= config.lastRow) {
html.push("<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;", "width:",
config.width, "px;", "top:",
(row - config.firstRow) * config.lineHeight,
"px;'></div>");
}
};
}
else
{
if (range.start.row >= config.firstRow && range.start.row <= config.lastRow)
{
html.push(
"<div class='", marker.clazz, "' style='",
"height:", config.lineHeight, "px;",
"width:", Math.round((range.end.column - range.start.column) * config.characterWidth), "px;",
"top:", (range.start.row-config.firstRow) * config.lineHeight, "px;",
"left:", Math.round(range.start.column * config.characterWidth), "px;'></div>"
);
;
}
else {
if (range.start.row >= config.firstRow
&& range.start.row <= config.lastRow) {
html.push("<div class='", marker.clazz, "' style='", "height:",
config.lineHeight, "px;", "width:",
Math.round((range.end.column - range.start.column)
* config.characterWidth), "px;", "top:",
(range.start.row - config.firstRow)
* config.lineHeight, "px;", "left:", Math
.round(range.start.column
* config.characterWidth),
"px;'></div>");
}
}
}

View file

@ -1,7 +1,7 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.TextDocument = function(text)
{
ace.TextDocument = function(text) {
this.lines = this._split(text);
this.modified = true;
@ -16,22 +16,20 @@ ace.TextDocument.prototype.addChangeListener = function(listener) {
this.listeners.push(listener);
};
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow)
{
for (var i=0; i < this.listeners.length; i++) {
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow) {
for ( var i = 0; i < this.listeners.length; i++) {
this.listeners[i](firstRow, lastRow);
};
}
;
};
ace.TextDocument.prototype.getWidth = function()
{
if (this.modified)
{
ace.TextDocument.prototype.getWidth = function() {
if (this.modified) {
this.modified = false;
var lines = this.lines;
var longestLine = 0;
for (var i=0; i < lines.length; i++) {
for ( var i = 0; i < lines.length; i++) {
longestLine = Math.max(longestLine, lines[i].length);
}
this.width = longestLine;
@ -69,8 +67,7 @@ ace.TextDocument.prototype.keywords = {
"with" : 1
};
ace.TextDocument.prototype.getLineTokens = function(row)
{
ace.TextDocument.prototype.getLineTokens = function(row) {
var tokens = [];
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
@ -78,23 +75,25 @@ ace.TextDocument.prototype.getLineTokens = function(row)
var match;
var line = this.getLine(row);
while (match = re.exec(line))
{
while (match = re.exec(line)) {
var token = {
type: "text",
value: match[0]
type : "text",
value : match[0]
}
if (match[2] || match[3]) {
token.type = "string";
} else if (match[5] && this.keywords[match[5]]) {
}
else if (match[5] && this.keywords[match[5]]) {
token.type = "keyword";
} else if (match[6]) {
}
else if (match[6]) {
token.type = "comment";
}
tokens.push(token);
};
}
;
return tokens;
};
@ -103,119 +102,111 @@ ace.TextDocument.prototype.getLength = function() {
return this.lines.length;
};
ace.TextDocument.prototype.getTextRange = function(range)
{
ace.TextDocument.prototype.getTextRange = function(range) {
if (range.start.row == range.end.row) {
return this.lines[range.start.row].substring(range.start.column, range.end.column);
} else {
return this.lines[range.start.row].substring(range.start.column,
range.end.column);
}
else {
var lines = [];
lines.push(this.lines[range.start.row].substring(range.start.column));
lines.push.apply(lines, this.lines.slice(range.start.row+1, range.end.row));
lines.push.apply(lines, this.lines.slice(range.start.row + 1,
range.end.row));
lines.push(this.lines[range.end.row].substring(0, range.end.column));
return lines.join("\n");
}
};
ace.TextDocument.prototype.insert = function(position, text)
{
ace.TextDocument.prototype.insert = function(position, text) {
var end = this._insert(position, text);
this.fireChangeEvent(
position.row,
position.row == end.row ? position.row : undefined
);
this.fireChangeEvent(position.row, position.row == end.row ? position.row
: undefined);
return end;
};
ace.TextDocument.prototype._insert = function(position, text)
{
ace.TextDocument.prototype._insert = function(position, text) {
this.modified = true;
var newLines = this._split(text);
if (text == "\n")
{
if (text == "\n") {
var line = this.lines[position.row] || "";
this.lines[position.row] = line.substring(0, position.column);
this.lines.splice(position.row+1, 0, line.substring(position.column));
this.lines.splice(position.row + 1, 0, line.substring(position.column));
return {
row: position.row + 1,
column: 0
row : position.row + 1,
column : 0
};
}
else if (newLines.length == 1)
{
else if (newLines.length == 1) {
var line = this.lines[position.row] || "";
this.lines[position.row] = line.substring(0, position.column) + text + line.substring(position.column);
this.lines[position.row] = line.substring(0, position.column) + text
+ line.substring(position.column);
return {
row: position.row,
column: position.column+text.length
row : position.row,
column : position.column + text.length
}
}
else
{
else {
var line = this.lines[position.row] || "";
this.lines[position.row] = line.substring(0, position.column) + newLines[0];
this.lines[position.row+1] = newLines[newLines.length-1] + line.substring(position.column);
this.lines[position.row] = line.substring(0, position.column)
+ newLines[0];
this.lines[position.row + 1] = newLines[newLines.length - 1]
+ line.substring(position.column);
if (newLines.length > 2)
{
var args = [position.row + 1, 0]
if (newLines.length > 2) {
var args = [ position.row + 1, 0 ]
args.push.apply(args, newLines.slice(1, -1));
this.lines.splice.apply(this.lines, args);
}
return {
row: position.row + newLines.length - 1,
column: newLines[newLines.length-1].length
row : position.row + newLines.length - 1,
column : newLines[newLines.length - 1].length
};
}
};
ace.TextDocument.prototype.remove = function(range)
{
ace.TextDocument.prototype.remove = function(range) {
var end = this._remove(range);
this.fireChangeEvent(
range.start.row,
range.end.row == range.start.row ? range.start.row : undefined
);
this.fireChangeEvent(range.start.row,
range.end.row == range.start.row ? range.start.row
: undefined);
return end;
};
ace.TextDocument.prototype._remove = function(range)
{
ace.TextDocument.prototype._remove = function(range) {
this.modified = true;
var firstRow = range.start.row;
var lastRow = range.end.row;
var row =
this.lines[firstRow].substring(0, range.start.column) +
this.lines[lastRow].substring(range.end.column);
var row = this.lines[firstRow].substring(0, range.start.column)
+ this.lines[lastRow].substring(range.end.column);
this.lines.splice(firstRow, lastRow-firstRow+1, row);
this.lines.splice(firstRow, lastRow - firstRow + 1, row);
return range.start;
};
ace.TextDocument.prototype.replace = function(range, text)
{
ace.TextDocument.prototype.replace = function(range, text) {
this._remove(range);
if (text) {
var end = this._insert(range.start, text);
} else {
}
else {
end = range.start;
}
var lastRemoved = range.end.column == 0 ? range.end.column-1 : range.end.column;
this.fireChangeEvent(
range.start.row,
lastRemoved == end.row ? lastRemoved : undefined
);
var lastRemoved = range.end.column == 0 ? range.end.column - 1
: range.end.column;
this.fireChangeEvent(range.start.row, lastRemoved == end.row ? lastRemoved
: undefined);
return end;
}

View file

@ -1,4 +1,5 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.TextInput = function(parentNode, host) {
@ -14,17 +15,18 @@ ace.TextInput = function(parentNode, host) {
var onTextInput = function(e) {
setTimeout(function() {
if (!inCompostion) {
if (text.value) host.onTextInput(text.value);
if (text.value)
host.onTextInput(text.value);
text.value = "";
}
}, 0)
}
var onCompositionStart = function(e)
{
var onCompositionStart = function(e) {
inCompostion = true;
if (text.value) host.onTextInput(text.value);
if (text.value)
host.onTextInput(text.value);
text.value = "";
host.onCompositionStart();
@ -35,8 +37,7 @@ ace.TextInput = function(parentNode, host) {
host.onCompositionUpdate(text.value);
}
var onCompositionEnd = function()
{
var onCompositionEnd = function() {
inCompostion = false;
host.onCompositionEnd();
onTextInput();

View file

@ -1,7 +1,7 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.TextLayer = function(parentEl)
{
ace.TextLayer = function(parentEl) {
this.element = document.createElement("div");
this.element.className = "layer text-layer";
parentEl.appendChild(this.element);
@ -21,8 +21,7 @@ ace.TextLayer.prototype.getCharacterWidth = function() {
return this.characterWidth;
};
ace.TextLayer.prototype._measureSizes = function()
{
ace.TextLayer.prototype._measureSizes = function() {
var measureNode = document.createElement("div");
var style = measureNode.style;
style.width = style.height = "auto";
@ -43,57 +42,49 @@ ace.TextLayer.prototype._measureSizes = function()
this.element.removeChild(measureNode);
};
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
{
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow) {
var first = Math.max(firstRow, layerConfig.firstRow);
var last = Math.min(lastRow, layerConfig.lastRow);
var lineElements = this.element.childNodes;
for (var i=first; i <= last; i++)
{
for ( var i = first; i <= last; i++) {
var html = [];
this.renderLine(html, i);
var lineElement = lineElements[i-layerConfig.firstRow];
var lineElement = lineElements[i - layerConfig.firstRow];
lineElement.innerHTML = html.join("");
};
}
;
};
ace.TextLayer.prototype.update = function(config)
{
ace.TextLayer.prototype.update = function(config) {
var html = [];
for (var i=config.firstRow; i<=config.lastRow; i++)
{
html.push(
"<div class='line ",
i % 2 == 0 ? "even" : "odd",
"' style='height:" + this.lineHeight + "px;",
"width:", config.width, "px'>"
);
this.renderLine(html, i),
html.push("</div>");
for ( var i = config.firstRow; i <= config.lastRow; i++) {
html.push("<div class='line ", i % 2 == 0 ? "even" : "odd",
"' style='height:" + this.lineHeight + "px;", "width:",
config.width, "px'>");
this.renderLine(html, i), html.push("</div>");
}
this.element.innerHTML = html.join("");
};
ace.TextLayer.prototype.renderLine = function(stringBuilder, row)
{
ace.TextLayer.prototype.renderLine = function(stringBuilder, row) {
var tokens = this.tokenizer.getTokens(row);
for (var i=0; i < tokens.length; i++)
{
for ( var i = 0; i < tokens.length; i++) {
var token = tokens[i];
var output = token.value.
replace(/&/g, "&amp;").
replace(/</g, "&lt;").
replace(/\s/g, "&nbsp;");
var output = token.value.replace(/&/g, "&amp;").replace(/</g, "&lt;")
.replace(/\s/g, "&nbsp;");
if (token.type !== "text") {
stringBuilder.push("<span class='", token.type, "'>", output, "</span>");
} else {
stringBuilder.push("<span class='", token.type, "'>", output,
"</span>");
}
else {
stringBuilder.push(output);
}
};
}
;
};

View file

@ -1,25 +1,25 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.Tokenizer = function(rules)
{
ace.Tokenizer = function(rules) {
this.rules = rules;
this.regExps = {};
for (var key in this.rules)
{
for ( var key in this.rules) {
var state = this.rules[key];
var ruleRegExps = [];
for (var i=0; i < state.length; i++) {
for ( var i = 0; i < state.length; i++) {
ruleRegExps.push(state[i].regex);
};
}
;
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g");
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
+ ")|(.))", "g");
}
};
ace.Tokenizer.prototype.getLineTokens = function(line, startState)
{
ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
var currentState = startState;
var state = this.rules[currentState];
var re = this.regExps[currentState];
@ -29,32 +29,27 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState)
var lastIndex = 0;
while (match = re.exec(line))
{
while (match = re.exec(line)) {
var token = {
type: "text",
value: match[0]
type : "text",
value : match[0]
}
if (re.lastIndex == lastIndex) {
throw new Error("tokenizer error")
}
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error") }
lastIndex = re.lastIndex;
//console.log(match);
// console.log(match);
for (var i=0; i < state.length; i++)
{
if (match[i+1])
{
for ( var i = 0; i < state.length; i++) {
if (match[i + 1]) {
if (typeof state[i].token == "function") {
token.type = state[i].token(match[0]);
} else {
}
else {
token.type = state[i].token;
}
if (state[i].next && state[i].next !== currentState)
{
if (state[i].next && state[i].next !== currentState) {
currentState = state[i].next;
var state = this.rules[currentState];
var lastIndex = re.lastIndex;
@ -64,15 +59,17 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState)
}
break;
}
};
}
;
tokens.push(token);
};
}
;
//console.log(tokens, currentState)
// console.log(tokens, currentState)
return {
tokens: tokens,
state: currentState
tokens : tokens,
state : currentState
}
};

View file

@ -1,7 +1,7 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
ace.VirtualRenderer = function(container)
{
ace.VirtualRenderer = function(container) {
this.container = container;
this.container.className += "editor";
@ -24,18 +24,17 @@ ace.VirtualRenderer = function(container)
this.cursorLayer = new ace.CursorLayer(this.scroller);
this.layers = [this.markerLayer, textLayer, this.cursorLayer];
this.layers = [ this.markerLayer, textLayer, this.cursorLayer ];
this.scrollTop = 0;
this.cursorPos = {
row: 0,
column: 0
row : 0,
column : 0
};
}
ace.VirtualRenderer.prototype.setDocument = function(doc)
{
ace.VirtualRenderer.prototype.setDocument = function(doc) {
this.lines = doc.lines;
this.doc = doc;
};
@ -56,18 +55,14 @@ ace.VirtualRenderer.prototype.getLastVisibleRow = function() {
return this.layerConfig.lastRow || 0;
};
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
{
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
var layerConfig = this.layerConfig;
// if the first row is below the viewport -> ignore it
if (firstRow > layerConfig.lastRow+1) {
return;
}
if (firstRow > layerConfig.lastRow + 1) { return; }
// if the last row is unknow -> redraw everything
if (lastRow === undefined)
{
if (lastRow === undefined) {
this.draw()
return;
}
@ -76,32 +71,29 @@ ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
};
ace.VirtualRenderer.prototype.draw = function()
{
ace.VirtualRenderer.prototype.draw = function() {
var lines = this.lines;
var offset = this.scrollTop % this.lineHeight;
var minHeight = this.scroller.clientHeight + offset;
var longestLine = Math.max(
this.scroller.clientWidth,
Math.round(this.doc.getWidth() * this.characterWidth)
);
var longestLine = Math.max(this.scroller.clientWidth, Math.round(this.doc
.getWidth()
* this.characterWidth));
var lineCount = Math.ceil(minHeight / this.lineHeight);
var firstRow = Math.round((this.scrollTop - offset) / this.lineHeight);
var lastRow = Math.min(lines.length, firstRow+lineCount)-1;
var lastRow = Math.min(lines.length, firstRow + lineCount) - 1;
var layerConfig = this.layerConfig = {
width: longestLine,
firstRow: firstRow,
lastRow: lastRow,
lineHeight: this.lineHeight,
characterWidth: this.characterWidth
width : longestLine,
firstRow : firstRow,
lastRow : lastRow,
lineHeight : this.lineHeight,
characterWidth : this.characterWidth
};
for (var i=0; i < this.layers.length; i++)
{
for ( var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
var style = layer.element.style;
@ -110,7 +102,8 @@ ace.VirtualRenderer.prototype.draw = function()
style.width = longestLine + "px";
layer.update(layerConfig);
};
}
;
this.gutterLayer.element.style.marginTop = (-offset) + "px";
this.gutterLayer.element.style.height = minHeight + "px";
@ -125,8 +118,7 @@ ace.VirtualRenderer.prototype.removeMarker = function(markerId) {
this.markerLayer.removeMarker(markerId);
};
ace.VirtualRenderer.prototype.updateCursor = function(position)
{
ace.VirtualRenderer.prototype.updateCursor = function(position) {
this.cursorLayer.setCursor(position);
this.cursorLayer.update(this.layerConfig);
};
@ -139,8 +131,7 @@ ace.VirtualRenderer.prototype.showCursor = function() {
this.cursorLayer.showCursor();
};
ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
{
ace.VirtualRenderer.prototype.scrollCursorIntoView = function() {
var pos = this.cursorLayer.getPixelPosition();
var left = pos.left
@ -150,7 +141,8 @@ ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
this.scrollToY(top);
}
if (this.getScrollTop() + this.scroller.clientHeight < top + this.lineHeight) {
if (this.getScrollTop() + this.scroller.clientHeight < top
+ this.lineHeight) {
this.scrollToY(top + this.lineHeight - this.scroller.clientHeight);
}
@ -158,8 +150,10 @@ ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
this.scroller.scrollLeft = left;
}
if (this.scroller.scrollLeft + this.scroller.clientWidth < left + this.characterWidth) {
this.scroller.scrollLeft = Math.round(left + this.characterWidth - this.scroller.clientWidth);
if (this.scroller.scrollLeft + this.scroller.clientWidth < left
+ this.characterWidth) {
this.scroller.scrollLeft = Math.round(left + this.characterWidth
- this.scroller.clientWidth);
}
},
@ -168,12 +162,12 @@ ace.VirtualRenderer.prototype.getScrollTop = function() {
};
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToY(row*this.lineHeight);
this.scrollToY(row * this.lineHeight);
}
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
{
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) {
var maxHeight = this.lines.length * this.lineHeight
- this.scroller.clientHeight;
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
if (this.scrollTop !== scrollTop) {
@ -182,16 +176,17 @@ ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
}
};
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
{
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left) / this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top) / this.lineHeight);
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left)
/ this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top)
/ this.lineHeight);
return {
row: row,
column: col
row : row,
column : col
}
};

View file

@ -1,98 +1,75 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
(function() {
ace.XML = {};
ace.XML = {};
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
ace.XML.RULES = {
start :
[
{
token: "text",
regex: "<\\!\\[CDATA\\[",
next: "cdata"
},
{
token: "xml_pe",
regex: "<\\?.*?\\?>"
},
{
token: "comment",
regex: "<\\!--",
next: "comment"
},
{
token: "text", // opening tag
regex: "<",
next: "tag"
},
{
token: "text",
regex: "\\s+"
},
{
token: "text",
regex: ".+"
}
],
ace.XML.RULES = {
start : [ {
token : "text",
regex : "<\\!\\[CDATA\\[",
next : "cdata"
}, {
token : "xml_pe",
regex : "<\\?.*?\\?>"
}, {
token : "comment",
regex : "<\\!--",
next : "comment"
}, {
token : "text", // opening tag
regex : "<",
next : "tag"
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : ".+"
} ],
tag:
[
{
token: "text",
regex: ">",
next: "start"
},
{
token: "keyword",
regex: "[-_a-zA-Z0-9:]+"
},
{
token: "text",
regex: "\\s+"
},
{
token: "string",
regex: '".*?"'
},
{
token: "string",
regex: "'.*?'"
}
],
tag : [ {
token : "text",
regex : ">",
next : "start"
}, {
token : "keyword",
regex : "[-_a-zA-Z0-9:]+"
}, {
token : "text",
regex : "\\s+"
}, {
token : "string",
regex : '".*?"'
}, {
token : "string",
regex : "'.*?'"
} ],
cdata:
[
{
token: "text",
regex: "\\]\\]>",
next: "start"
},
{
token: "text",
regex: "\\s+"
},
{
token: "text",
regex: ".+"
}
],
cdata : [ {
token : "text",
regex : "\\]\\]>",
next : "start"
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : ".+"
} ],
comment:
[
{
token: "comment",
regex: ".*?-->",
next: "start"
},
{
token: "comment",
regex: ".+"
}
]
};
comment : [ {
token : "comment",
regex : ".*?-->",
next : "start"
}, {
token : "comment",
regex : ".+"
} ]
};
})();

View file

@ -1,11 +1,12 @@
if (!window.ace) ace = {};
if (!window.ace)
ace = {};
(function() {
ace.addListener = function(elem, type, callback) {
if (elem.addEventListener) {
return elem.addEventListener(type, callback, false);
}
if (elem.addEventListener) { return elem.addEventListener(type,
callback,
false); }
if (elem.attachEvent) {
var wrapper = function() {
callback(window.event);
@ -16,9 +17,8 @@ ace.addListener = function(elem, type, callback) {
}
ace.removeListener = function(elem, type, callback) {
if (elem.removeEventListener) {
return elem.removeEventListener(type, callback, false);
}
if (elem.removeEventListener) { return elem
.removeEventListener(type, callback, false); }
if (elem.detachEvent) {
elem.detachEvent("on" + type, callback.$$wrapper || callback);
}
@ -46,8 +46,7 @@ ace.stopPropagation = function(e) {
e.cancelBubble = true;
}
ace.preventDefault = function(e)
{
ace.preventDefault = function(e) {
if (e.preventDefault)
e.preventDefault();
else
@ -55,36 +54,29 @@ ace.preventDefault = function(e)
}
ace.inherits = function(ctor, superCtor) {
var tempCtor = function(){};
var tempCtor = function() {
};
tempCtor.prototype = superCtor.prototype;
ctor.super_ = superCtor.prototype;
ctor.prototype = new tempCtor();
ctor.prototype.constructor = ctor;
};
ace.getInnerWidth = function(element)
{
return (
parseInt(ace.computedStyle(element, "paddingLeft")) +
parseInt(ace.computedStyle(element, "paddingRight")) +
element.clientWidth
);
ace.getInnerWidth = function(element) {
return (parseInt(ace.computedStyle(element, "paddingLeft"))
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
};
ace.getInnerHeight = function(element)
{
return (
parseInt(ace.computedStyle(element, "paddingTop")) +
parseInt(ace.computedStyle(element, "paddingBottom")) +
element.clientHeight
);
ace.getInnerHeight = function(element) {
return (parseInt(ace.computedStyle(element, "paddingTop"))
+ parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight);
};
ace.computedStyle = function(element, style)
{
ace.computedStyle = function(element, style) {
if (window.getComputedStyle) {
return (window.getComputedStyle(element, null))[style];
} else {
}
else {
return element.currentStyle[style];
}
}
@ -111,16 +103,13 @@ ace.bind = function(fcn, context) {
}
}
ace.capture = function(el, eventHandler, releaseCaptureHandler)
{
function onMouseMove(e)
{
ace.capture = function(el, eventHandler, releaseCaptureHandler) {
function onMouseMove(e) {
eventHandler(e);
e.stopPropagation();
}
function onMouseUp(e)
{
function onMouseUp(e) {
eventHandler && eventHandler(e);
releaseCaptureHandler && releaseCaptureHandler();
@ -134,20 +123,18 @@ ace.capture = function(el, eventHandler, releaseCaptureHandler)
document.addEventListener("mouseup", onMouseUp, true);
}
ace.addMouseWheelListener = function(el, callback)
{
ace.addMouseWheelListener = function(el, callback) {
var listener = function(e) {
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
: -(e.detail || 0) / 3;
callback(e);
}
ace.addListener(el, "DOMMouseScroll", listener);
ace.addListener(el, "mousewheel", listener);
};
ace.autoremoveListener = function(el, type, callback, timeout)
{
var listener = function(e)
{
ace.autoremoveListener = function(el, type, callback, timeout) {
var listener = function(e) {
clearTimeout(timeoutId);
remove();
callback(e);
@ -161,8 +148,7 @@ ace.autoremoveListener = function(el, type, callback, timeout)
var timeoutId = setTimeout(remove, timeout);
}
ace.addTripleClickListener = function(el, callback)
{
ace.addTripleClickListener = function(el, callback) {
ace.addListener(el, "mousedown", function() {
ace.autoremoveListener(el, "mousedown", function() {
ace.autoremoveListener(el, "mousedown", callback, 300);