use APF style class declaration

This commit is contained in:
Fabian Jakobs 2010-04-22 13:25:44 +02:00
commit 2b736e7c8e
20 changed files with 1945 additions and 1867 deletions

View file

@ -41,31 +41,34 @@ ace.BackgroundTokenizer = function(tokenizer) {
this.$initEvents();
};
ace.mixin(ace.BackgroundTokenizer.prototype, ace.MEventEmitter);
ace.BackgroundTokenizer.prototype.setTokenizer = function(tokenizer) {
(function(){
ace.mixin(this, ace.MEventEmitter);
this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer;
this.lines = [];
this.start(0);
};
};
ace.BackgroundTokenizer.prototype.setLines = function(textLines) {
this.setLines = function(textLines) {
this.textLines = textLines;
this.lines = [];
this.stop();
};
};
ace.BackgroundTokenizer.prototype.fireUpdateEvent = function(firstRow, lastRow) {
this.fireUpdateEvent = function(firstRow, lastRow) {
var data = {
first: firstRow,
last: lastRow
};
this.$dispatchEvent("update", {data: data});
};
};
ace.BackgroundTokenizer.prototype.start = function(startRow) {
this.start = function(startRow) {
this.currentLine = Math.min(startRow || 0, this.currentLine,
this.textLines.length);
@ -76,21 +79,21 @@ ace.BackgroundTokenizer.prototype.start = function(startRow) {
// pretty long delay to prevent the tokenizer from interfering with the user
this.running = setTimeout(this._worker, 200);
}
};
};
ace.BackgroundTokenizer.prototype.stop = function() {
this.stop = function() {
this.running = false;
};
};
ace.BackgroundTokenizer.prototype.getTokens = function(row) {
this.getTokens = function(row) {
return this._tokenizeRow(row).tokens;
};
};
ace.BackgroundTokenizer.prototype.getState = function(row) {
this.getState = function(row) {
return this._tokenizeRow(row).state;
};
};
ace.BackgroundTokenizer.prototype._tokenizeRow = function(row) {
this._tokenizeRow = function(row) {
if (!this.lines[row]) {
var state = "start";
if (row > 0 && this.lines[row - 1]) {
@ -99,4 +102,6 @@ ace.BackgroundTokenizer.prototype._tokenizeRow = function(row) {
this.lines[row] = this.tokenizer.getLineTokens(this.textLines[row] || "", state);
}
return this.lines[row];
};
};
}).call(ace.BackgroundTokenizer.prototype);

View file

@ -13,86 +13,88 @@ ace.Document = function(text, mode) {
}
};
ace.mixin(ace.Document.prototype, ace.MEventEmitter);
(function() {
ace.Document.prototype._split = function(text) {
ace.mixin(ace.Document.prototype, ace.MEventEmitter);
this._split = function(text) {
return text.split(/\r\n|\r|\n/);
};
};
ace.Document.prototype.toString = function() {
this.toString = function() {
return this.lines.join("\n");
};
};
ace.Document.prototype.getSelection = function() {
this.getSelection = function() {
return this.selection;
};
};
ace.Document.prototype.fireChangeEvent = function(firstRow, lastRow) {
this.fireChangeEvent = function(firstRow, lastRow) {
var data = {
firstRow: firstRow,
lastRow: lastRow
};
this.$dispatchEvent("change", { data: data});
};
};
ace.Document.prototype.getTabString = function() {
this.getTabString = function() {
if (this.getUseSoftTabs()) {
return new Array(this.getTabSize()+1).join(" ");
}
return "\t";
};
};
ace.Document.prototype._useSoftTabs = true;
ace.Document.prototype.setUseSoftTabs = function(useSoftTabs) {
this._useSoftTabs = false;
this.setUseSoftTabs = function(useSoftTabs) {
if (this._useSoftTabs === useSoftTabs) return;
this._useSoftTabs = useSoftTabs;
};
};
ace.Document.prototype.getUseSoftTabs = function() {
this.getUseSoftTabs = function() {
return this._useSoftTabs;
};
};
ace.Document.prototype._tabSize = 4;
ace.Document.prototype.setTabSize = function(tabSize) {
this._tabSize = 4;
this.setTabSize = function(tabSize) {
if (this._tabSize === tabSize) return;
this._tabSize = tabSize;
this.$dispatchEvent("changeTabSize");
};
};
ace.Document.prototype.getTabSize = function() {
this.getTabSize = function() {
return this._tabSize;
};
};
ace.Document.prototype._mode = null;
ace.Document.prototype.setMode = function(mode) {
this._mode = null;
this.setMode = function(mode) {
if (this._mode === mode) return;
this._mode = mode;
this.$dispatchEvent("changeMode");
};
};
ace.Document.prototype.getMode = function() {
this.getMode = function() {
if (!this._mode) {
this._mode = new ace.mode.Text();
}
return this._mode;
};
};
ace.Document.prototype._scrollTop = 0;
ace.Document.prototype.setScrollTopRow = function(scrollTopRow) {
this._scrollTop = 0;
this.setScrollTopRow = function(scrollTopRow) {
if (this._scrollTop === scrollTopRow) return;
this._scrollTop = scrollTopRow;
this.$dispatchEvent("changeScrollTop");
};
};
ace.Document.prototype.getScrollTopRow = function() {
this.getScrollTopRow = function() {
return this._scrollTop;
};
};
ace.Document.prototype.getWidth = function() {
this.getWidth = function() {
if (this.modified) {
this.modified = false;
@ -104,17 +106,17 @@ ace.Document.prototype.getWidth = function() {
this.width = longestLine;
}
return this.width;
};
};
ace.Document.prototype.getLine = function(row) {
this.getLine = function(row) {
return this.lines[row] || "";
};
};
ace.Document.prototype.getLength = function() {
this.getLength = function() {
return this.lines.length;
};
};
ace.Document.prototype.getTextRange = function(range) {
this.getTextRange = function(range) {
if (range.start.row == range.end.row) {
return this.lines[range.start.row].substring(range.start.column,
range.end.column);
@ -126,13 +128,13 @@ ace.Document.prototype.getTextRange = function(range) {
lines.push(this.lines[range.end.row].substring(0, range.end.column));
return lines.join("\n");
}
};
};
ace.Document.prototype.getLines = function(firstRow, lastRow) {
this.getLines = function(firstRow, lastRow) {
return this.lines.slice(firstRow, lastRow+1);
};
};
ace.Document.prototype.findMatchingBracket = function(position) {
this.findMatchingBracket = function(position) {
if (position.column == 0) return null;
var charBeforeCursor = this.getLine(position.row).charAt(position.column-1);
@ -148,18 +150,18 @@ ace.Document.prototype.findMatchingBracket = function(position) {
} else {
return this._findOpeningBracket(match[2], position);
}
};
};
ace.Document.prototype._brackets = {
this._brackets = {
")": "(",
"(": ")",
"]": "[",
"[": "]",
"{": "}",
"}": "{"
};
};
ace.Document.prototype._findOpeningBracket = function(bracket, position) {
this._findOpeningBracket = function(bracket, position) {
var openBracket = this._brackets[bracket];
var column = position.column - 2;
@ -189,9 +191,9 @@ ace.Document.prototype._findOpeningBracket = function(bracket, position) {
var column = line.length-1;
}
return null;
};
};
ace.Document.prototype._findClosingBracket = function(bracket, position) {
this._findClosingBracket = function(bracket, position) {
var closingBracket = this._brackets[bracket];
var column = position.column;
@ -222,22 +224,22 @@ ace.Document.prototype._findClosingBracket = function(bracket, position) {
var column = 0;
}
return null;
};
};
ace.Document.prototype.insert = function(position, text) {
this.insert = function(position, text) {
var end = this._insert(position, text);
this.fireChangeEvent(position.row, position.row == end.row ? position.row
: undefined);
return end;
};
};
ace.Document.prototype._insertLines = function(row, lines) {
this._insertLines = function(row, lines) {
var args = [row, 0];
args.push.apply(args, lines);
this.lines.splice.apply(this.lines, args);
},
},
ace.Document.prototype._insert = function(position, text) {
this._insert = function(position, text) {
this.modified = true;
var newLines = this._split(text);
@ -279,22 +281,22 @@ ace.Document.prototype._insert = function(position, text) {
column : newLines[newLines.length - 1].length
};
}
};
};
ace.Document.prototype._isNewLine = function(text) {
this._isNewLine = function(text) {
return (text == "\r\n" || text == "\r" || text == "\n");
};
};
ace.Document.prototype.remove = function(range) {
this.remove = function(range) {
this._remove(range);
this.fireChangeEvent(range.start.row,
range.end.row == range.start.row ? range.start.row
: undefined);
return range.start;
};
};
ace.Document.prototype._remove = function(range) {
this._remove = function(range) {
this.modified = true;
var firstRow = range.start.row;
@ -306,9 +308,9 @@ ace.Document.prototype._remove = function(range) {
this.lines.splice(firstRow, lastRow - firstRow + 1, row);
return range.start;
};
};
ace.Document.prototype.replace = function(range, text) {
this.replace = function(range, text) {
this._remove(range);
if (text) {
var end = this._insert(range.start, text);
@ -323,17 +325,17 @@ ace.Document.prototype.replace = function(range, text) {
: undefined);
return end;
};
};
ace.Document.prototype.indentRows = function(range, indentString) {
this.indentRows = function(range, indentString) {
for (var i=range.start.row; i<= range.end.row; i++) {
this.lines[i] = indentString + this.getLine(i);
}
this.fireChangeEvent(range.start.row, range.end.row);
return indentString.length;
};
};
ace.Document.prototype.outdentRows = function(range, indentString) {
this.outdentRows = function(range, indentString) {
outdentLength = indentString.length;
for (var i=range.start.row; i<= range.end.row; i++) {
@ -348,9 +350,9 @@ ace.Document.prototype.outdentRows = function(range, indentString) {
this.fireChangeEvent(range.start.row, range.end.row);
return -outdentLength;
};
};
ace.Document.prototype.moveLinesUp = function(firstRow, lastRow) {
this.moveLinesUp = function(firstRow, lastRow) {
if (firstRow <= 0) return 0;
var removed = this.lines.splice(firstRow, lastRow-firstRow+1);
@ -358,9 +360,9 @@ ace.Document.prototype.moveLinesUp = function(firstRow, lastRow) {
this.fireChangeEvent(firstRow-1, lastRow);
return -1;
};
};
ace.Document.prototype.moveLinesDown = function(firstRow, lastRow) {
this.moveLinesDown = function(firstRow, lastRow) {
if (lastRow >= this.lines.length-1) return 0;
var removed = this.lines.splice(firstRow, lastRow-firstRow+1);
@ -368,9 +370,9 @@ ace.Document.prototype.moveLinesDown = function(firstRow, lastRow) {
this.fireChangeEvent(firstRow, lastRow+1);
return 1;
};
};
ace.Document.prototype.duplicateLines = function(firstRow, lastRow) {
this.duplicateLines = function(firstRow, lastRow) {
var firstRow = this._clipRowToDocument(firstRow);
var lastRow = this._clipRowToDocument(lastRow);
@ -381,9 +383,10 @@ ace.Document.prototype.duplicateLines = function(firstRow, lastRow) {
this.fireChangeEvent(firstRow, lastRow+addedRows);
return addedRows;
};
};
ace.Document.prototype._clipRowToDocument = function(row) {
this._clipRowToDocument = function(row) {
return Math.max(0, Math.min(row, this.lines.length-1));
};
};
}).call(ace.Document.prototype);

View file

@ -26,8 +26,9 @@ ace.Editor = function(renderer, doc) {
this.setDocument(doc || new ace.Document(""));
};
(function(){
ace.Editor.prototype.setDocument = function(doc) {
this.setDocument = function(doc) {
if (this.doc == doc) return;
if (this.doc) {
@ -69,21 +70,21 @@ ace.Editor.prototype.setDocument = function(doc) {
this.onCursorChange();
this.onSelectionChange();
this.renderer.scrollToRow(doc.getScrollTopRow());
};
};
ace.Editor.prototype.getDocument = function() {
this.getDocument = function() {
return this.doc;
};
};
ace.Editor.prototype.getSelection = function() {
this.getSelection = function() {
return this.selection;
};
};
ace.Editor.prototype.resize = function() {
this.resize = function() {
this.renderer.onResize();
};
};
ace.Editor.prototype._highlightBrackets = function() {
this._highlightBrackets = function() {
if (this._bracketHighlight) {
this.renderer.removeMarker(this._bracketHighlight);
this._bracketHighlight = null;
@ -111,38 +112,38 @@ ace.Editor.prototype._highlightBrackets = function() {
self._bracketHighlight = self.renderer.addMarker(range, "bracket");
}
}, 10);
};
};
ace.Editor.prototype.focus = function() {
this.focus = function() {
this.textInput.focus();
};
};
ace.Editor.prototype.blur = function() {
this.blur = function() {
this.textInput.blur();
};
};
ace.Editor.prototype.onFocus = function() {
this.onFocus = function() {
this.renderer.showCursor();
this.renderer.visualizeFocus();
};
};
ace.Editor.prototype.onBlur = function() {
this.onBlur = function() {
this.renderer.hideCursor();
this.renderer.visualizeBlur();
};
};
ace.Editor.prototype.onDocumentChange = function(e) {
this.onDocumentChange = function(e) {
var data = e.data;
this.bgTokenizer.start(data.firstRow);
this.renderer.updateLines(data.firstRow, data.lastRow);
};
};
ace.Editor.prototype.onTokenizerUpdate = function(e) {
this.onTokenizerUpdate = function(e) {
var rows = e.data;
this.renderer.updateLines(rows.first, rows.last);
};
};
ace.Editor.prototype.onCursorChange = function() {
this.onCursorChange = function() {
this._highlightBrackets();
this.renderer.updateCursor(this.getCursorPosition());
@ -150,9 +151,9 @@ ace.Editor.prototype.onCursorChange = function() {
this.renderer.scrollCursorIntoView();
}
this._updateHighlightActiveLine();
};
};
ace.Editor.prototype._updateHighlightActiveLine = function() {
this._updateHighlightActiveLine = function() {
if (this._highlightLineMarker) {
this.renderer.removeMarker(this._highlightLineMarker);
}
@ -172,9 +173,9 @@ ace.Editor.prototype._updateHighlightActiveLine = function() {
};
this._highlightLineMarker = this.renderer.addMarker(range, "active_line", "line");
}
};
};
ace.Editor.prototype.onSelectionChange = function() {
this.onSelectionChange = function() {
if (this._selectionMarker) {
this.renderer.removeMarker(this._selectionMarker);
}
@ -187,9 +188,9 @@ ace.Editor.prototype.onSelectionChange = function() {
}
this.onCursorChange();
};
};
ace.Editor.prototype.onDocumentModeChange = function() {
this.onDocumentModeChange = function() {
var mode = this.doc.getMode();
this.mode = mode;
@ -205,10 +206,10 @@ ace.Editor.prototype.onDocumentModeChange = function() {
this.renderer.setTokenizer(this.bgTokenizer);
this.renderer.draw();
};
};
ace.Editor.prototype.onMouseDown = function(e) {
this.onMouseDown = function(e) {
var pageX = ace.getDocumentX(e);
var pageY = ace.getDocumentY(e);
@ -244,39 +245,39 @@ ace.Editor.prototype.onMouseDown = function(e) {
var timerId = setInterval(onSelectionInterval, 20);
return ace.preventDefault(e);
};
};
ace.Editor.prototype.onMouseDoubleClick = function(e) {
this.onMouseDoubleClick = function(e) {
this.selection.selectWord();
};
};
ace.Editor.prototype.onMouseTripleClick = function(e) {
this.onMouseTripleClick = function(e) {
this.selection.selectLine();
};
};
ace.Editor.prototype.onMouseWheel = function(e) {
this.onMouseWheel = function(e) {
var delta = e.wheel;
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
return ace.preventDefault(e);
};
};
ace.Editor.prototype.getCopyText = function() {
this.getCopyText = function() {
if (!this.selection.isEmpty()) {
return this.doc.getTextRange(this.getSelectionRange());
}
else {
return "";
}
};
};
ace.Editor.prototype.onCut = function() {
this.onCut = function() {
if (!this.selection.isEmpty()) {
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.clearSelection();
}
};
};
ace.Editor.prototype.onTextInput = function(text) {
this.onTextInput = function(text) {
var cursor = this.getCursorPosition();
if (this.doc.getUseSoftTabs()) {
@ -311,63 +312,63 @@ ace.Editor.prototype.onTextInput = function(text) {
this.moveCursorToPosition(end);
this.renderer.scrollCursorIntoView();
};
};
ace.Editor.prototype._selectionStyle = "line";
ace.Editor.prototype.setSelectionStyle = function(style) {
this._selectionStyle = "line";
this.setSelectionStyle = function(style) {
if (this._selectionStyle == style) return;
this._selectionStyle = style;
this.onSelectionChange();
};
};
ace.Editor.prototype.getSelectionStyle = function() {
this.getSelectionStyle = function() {
return this._selectionStyle;
};
};
ace.Editor.prototype._highlightActiveLine = true;
ace.Editor.prototype.setHighlightActiveLine = function(shouldHighlight) {
this._highlightActiveLine = true;
this.setHighlightActiveLine = function(shouldHighlight) {
if (this._highlightActiveLine == shouldHighlight) return;
this._highlightActiveLine = shouldHighlight;
this._updateHighlightActiveLine();
};
};
ace.Editor.prototype.getHighlightActiveLine = function() {
this.getHighlightActiveLine = function() {
return this._highlightActiveLine;
};
};
ace.Editor.prototype.removeRight = function() {
this.removeRight = function() {
if (this.selection.isEmpty()) {
this.selection.selectRight();
}
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.clearSelection();
};
};
ace.Editor.prototype.removeLeft = function() {
this.removeLeft = function() {
if (this.selection.isEmpty()) {
this.selection.selectLeft();
}
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.clearSelection();
};
};
ace.Editor.prototype.blockIndent = function(indentString) {
this.blockIndent = function(indentString) {
var indentString = indentString || this.doc.getTabString();
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
this.selection.shiftSelection(addedColumns);
};
};
ace.Editor.prototype.blockOutdent = function(indentString) {
this.blockOutdent = function(indentString) {
var indentString = indentString || this.doc.getTabString();
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString);
this.selection.shiftSelection(addedColumns);
};
};
ace.Editor.prototype.toggleCommentLines = function() {
this.toggleCommentLines = function() {
var rows = this._getSelectedRows();
var range = {
@ -384,44 +385,44 @@ ace.Editor.prototype.toggleCommentLines = function() {
var addedColumns = this.mode.toggleCommentLines(this.doc, range, state);
this.selection.shiftSelection(addedColumns);
};
};
ace.Editor.prototype.removeLines = function() {
this.removeLines = function() {
var rows = this._getSelectedRows();
this.selection.setSelectionAnchor(rows.last+1, 0);
this.selection.selectTo(rows.first, 0);
this.doc.remove(this.getSelectionRange());
this.clearSelection();
};
};
ace.Editor.prototype.moveLinesDown = function() {
this.moveLinesDown = function() {
this._moveLines(function(firstRow, lastRow) {
return this.doc.moveLinesDown(firstRow, lastRow);
});
};
};
ace.Editor.prototype.moveLinesUp = function() {
this.moveLinesUp = function() {
this._moveLines(function(firstRow, lastRow) {
return this.doc.moveLinesUp(firstRow, lastRow);
});
};
};
ace.Editor.prototype.copyLinesUp = function() {
this.copyLinesUp = function() {
this._moveLines(function(firstRow, lastRow) {
this.doc.duplicateLines(firstRow, lastRow);
return 0;
});
};
};
ace.Editor.prototype.copyLinesDown = function() {
this.copyLinesDown = function() {
this._moveLines(function(firstRow, lastRow) {
return this.doc.duplicateLines(firstRow, lastRow);
});
};
};
ace.Editor.prototype._moveLines = function(mover) {
this._moveLines = function(mover) {
var rows = this._getSelectedRows();
var linesMoved = mover.call(this, rows.first, rows.last);
@ -431,9 +432,9 @@ ace.Editor.prototype._moveLines = function(mover) {
selection._moveSelection(function() {
selection.moveCursorTo(rows.first+linesMoved, 0);
});
};
};
ace.Editor.prototype._getSelectedRows = function() {
this._getSelectedRows = function() {
var range = this.getSelectionRange();
var firstRow = range.start.row;
var lastRow = range.end.row;
@ -445,86 +446,86 @@ ace.Editor.prototype._getSelectedRows = function() {
first: firstRow,
last: lastRow
};
};
};
ace.Editor.prototype.onCompositionStart = function() {
this.onCompositionStart = function() {
this.renderer.showComposition(this.getCursorPosition());
this.onTextInput(" ");
};
};
ace.Editor.prototype.onCompositionUpdate = function(text) {
this.onCompositionUpdate = function(text) {
this.renderer.setCompositionText(text);
};
};
ace.Editor.prototype.onCompositionEnd = function() {
this.onCompositionEnd = function() {
this.renderer.hideComposition();
this.removeLeft();
};
};
ace.Editor.prototype.getFirstVisibleRow = function() {
this.getFirstVisibleRow = function() {
return this.renderer.getFirstVisibleRow();
};
};
ace.Editor.prototype.getLastVisibleRow = function() {
this.getLastVisibleRow = function() {
return this.renderer.getLastVisibleRow();
};
};
ace.Editor.prototype.isRowVisible = function(row) {
this.isRowVisible = function(row) {
return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
};
};
ace.Editor.prototype.getVisibleRowCount = function() {
this.getVisibleRowCount = function() {
return this.getLastVisibleRow() - this.getFirstVisibleRow() + 1;
};
};
ace.Editor.prototype.getPageDownRow = function() {
this.getPageDownRow = function() {
return this.renderer.getLastVisibleRow() - 1;
};
};
ace.Editor.prototype.getPageUpRow = function() {
this.getPageUpRow = function() {
var firstRow = this.renderer.getFirstVisibleRow();
var lastRow = this.renderer.getLastVisibleRow();
return firstRow - (lastRow - firstRow) + 1;
};
};
ace.Editor.prototype.scrollPageDown = function() {
this.scrollPageDown = function() {
this.scrollToRow(this.getPageDownRow());
};
};
ace.Editor.prototype.scrollPageUp = function() {
this.scrollPageUp = function() {
this.renderer.scrollToRow(this.getPageUpRow());
};
};
ace.Editor.prototype.scrollToRow = function(row) {
this.scrollToRow = function(row) {
this.renderer.scrollToRow(row);
};
};
ace.Editor.prototype.getCursorPosition = function() {
this.getCursorPosition = function() {
return this.selection.getCursor();
};
};
ace.Editor.prototype.getSelectionRange = function() {
this.getSelectionRange = function() {
return this.selection.getRange();
};
};
ace.Editor.prototype.clearSelection = function() {
this.clearSelection = function() {
this.selection.clearSelection();
};
};
ace.Editor.prototype.moveCursorTo = function(row, column) {
this.moveCursorTo = function(row, column) {
this.selection.moveCursorTo(row, column);
};
};
ace.Editor.prototype.moveCursorToPosition = function(pos) {
this.moveCursorToPosition = function(pos) {
this.selection.moveCursorToPosition(pos);
};
};
ace.Editor.prototype.gotoLine = function(lineNumber) {
this.gotoLine = function(lineNumber) {
this._blockScrolling = true;
this.moveCursorTo(lineNumber-1, 0);
this._blockScrolling = false;
@ -532,24 +533,24 @@ ace.Editor.prototype.gotoLine = function(lineNumber) {
if (!this.isRowVisible(this.getCursorPosition().row)) {
this.scrollToRow(lineNumber - 1 - Math.floor(this.getVisibleRowCount() / 2));
}
},
},
ace.Editor.prototype.navigateTo = function(row, column) {
this.navigateTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
};
};
ace.Editor.prototype.navigateUp = function() {
this.navigateUp = function() {
this.clearSelection();
this.selection.moveCursorUp();
};
};
ace.Editor.prototype.navigateDown = function() {
this.navigateDown = function() {
this.clearSelection();
this.selection.moveCursorDown();
};
};
ace.Editor.prototype.navigateLeft = function() {
this.navigateLeft = function() {
if (!this.selection.isEmpty()) {
var selectionStart = this.getSelectionRange().start;
this.moveCursorToPosition(selectionStart);
@ -558,9 +559,9 @@ ace.Editor.prototype.navigateLeft = function() {
this.selection.moveCursorLeft();
}
this.clearSelection();
};
};
ace.Editor.prototype.navigateRight = function() {
this.navigateRight = function() {
if (!this.selection.isEmpty()) {
var selectionEnd = this.getSelectionRange().end;
this.moveCursorToPosition(selectionEnd);
@ -569,34 +570,35 @@ ace.Editor.prototype.navigateRight = function() {
this.selection.moveCursorRight();
}
this.clearSelection();
};
};
ace.Editor.prototype.navigateLineStart = function() {
this.navigateLineStart = function() {
this.clearSelection();
this.selection.moveCursorLineStart();
};
};
ace.Editor.prototype.navigateLineEnd = function() {
this.navigateLineEnd = function() {
this.clearSelection();
this.selection.moveCursorLineEnd();
};
};
ace.Editor.prototype.navigateFileEnd = function() {
this.navigateFileEnd = function() {
this.clearSelection();
this.selection.moveCursorFileEnd();
};
};
ace.Editor.prototype.navigateFileStart = function() {
this.navigateFileStart = function() {
this.clearSelection();
this.selection.moveCursorFileStart();
};
};
ace.Editor.prototype.navigateWordRight = function() {
this.navigateWordRight = function() {
this.clearSelection();
this.selection.moveCursorWordRight();
};
};
ace.Editor.prototype.navigateWordLeft = function() {
this.navigateWordLeft = function() {
this.clearSelection();
this.selection.moveCursorWordLeft();
};
};
}).call(ace.Editor.prototype);

View file

@ -1,26 +1,9 @@
ace.provide("ace.KeyBinding");
(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,
D: 68,
L: 76,
"7": 55
};
ace.KeyBinding = function(element, editor) {
var keys = this.keys;
ace.addListener(element, "keydown", function(e) {
var key = e.keyCode;
var selection = editor.getSelection();
@ -198,4 +181,22 @@ ace.KeyBinding = function(element, editor) {
});
};
})();
(function() {
this.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,
D: 68,
L: 76,
"7": 55
};
}).call(ace.KeyBinding.prototype);

View file

@ -17,24 +17,28 @@ ace.ScrollBar = function(parent) {
ace.addListener(this.element, "scroll", ace.bind(this.onScroll, this));
};
ace.mixin(ace.ScrollBar.prototype, ace.MEventEmitter);
(function() {
ace.ScrollBar.prototype.onScroll = function() {
ace.mixin(ace.ScrollBar.prototype, ace.MEventEmitter);
this.onScroll = function() {
this.$dispatchEvent("scroll", {data: this.element.scrollTop});
};
};
ace.ScrollBar.prototype.getWidth = function() {
this.getWidth = function() {
return this.width;
};
};
ace.ScrollBar.prototype.setHeight = function(height) {
this.setHeight = function(height) {
this.element.style.height = Math.max(0, height - this.width) + "px";
};
};
ace.ScrollBar.prototype.setInnerHeight = function(height) {
this.setInnerHeight = function(height) {
this.inner.style.height = height + "px";
};
};
ace.ScrollBar.prototype.setScrollTop = function(scrollTop) {
this.setScrollTop = function(scrollTop) {
this.element.scrollTop = scrollTop;
};
};
}).call(ace.ScrollBar.prototype);

View file

@ -11,52 +11,55 @@ ace.Selection = function(doc) {
column: 0
};
};
ace.mixin(ace.Selection.prototype, ace.MEventEmitter);
ace.Selection.prototype.updateCursor = function() {
(function() {
ace.mixin(ace.Selection.prototype, ace.MEventEmitter);
this.updateCursor = function() {
this.$dispatchEvent("changeCursor", { data: this.getCursor() });
};
};
ace.Selection.prototype.updateSelection = function() {
this.updateSelection = function() {
this.$dispatchEvent("changeSelection", {});
};
};
ace.Selection.prototype.isEmpty = function() {
this.isEmpty = function() {
return (this.selectionAnchor == null);
};
};
ace.Selection.prototype.isMultiLine = function() {
this.isMultiLine = function() {
if (this.isEmpty()) {
return false;
}
var range = this.getRange();
return (range.start.row !== range.end.row);
};
};
ace.Selection.prototype.getCursor = function() {
this.getCursor = function() {
return this.selectionLead;
};
};
ace.Selection.prototype.setSelectionAnchor = function(row, column) {
this.setSelectionAnchor = function(row, column) {
this.clearSelection();
this.selectionAnchor = this._clipPositionToDocument(row, column);
};
};
ace.Selection.prototype.getSelectionAnchor = function() {
this.getSelectionAnchor = function() {
if (this.selectionAnchor) {
return this._clone(this.selectionAnchor);
} else {
return this._clone(this.selectionLead);
}
};
};
ace.Selection.prototype.getSelectionLead = function() {
this.getSelectionLead = function() {
return this._clone(this.selectionLead);
};
};
ace.Selection.prototype.shiftSelection = function(columns) {
this.shiftSelection = function(columns) {
if (this.isEmpty()) {
this.moveCursorTo(this.selectionLead.row, this.selectionLead.column + columns);
return;
@ -69,9 +72,9 @@ ace.Selection.prototype.shiftSelection = function(columns) {
this._moveSelection(function() {
this.moveCursorTo(lead.row, lead.column + columns);
});
};
};
ace.Selection.prototype.getRange = function() {
this.getRange = function() {
var anchor = this.selectionAnchor || this.selectionLead;
var lead = this.selectionLead;
@ -88,69 +91,69 @@ ace.Selection.prototype.getRange = function() {
end : lead
};
}
};
};
ace.Selection.prototype.clearSelection = function() {
this.clearSelection = function() {
this.selectionAnchor = null;
this.updateSelection();
};
};
ace.Selection.prototype.selectAll = function() {
this.selectAll = function() {
var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
this._moveSelection(function() {
this.moveCursorTo(0, 0);
});
};
};
ace.Selection.prototype._moveSelection = function(mover) {
this._moveSelection = function(mover) {
if (!this.selectionAnchor) {
this.selectionAnchor = this._clone(this.selectionLead);
}
mover.call(this);
this.updateSelection();
};
};
ace.Selection.prototype.selectTo = function(row, column) {
this.selectTo = function(row, column) {
this._moveSelection(function() {
this.moveCursorTo(row, column);
});
};
};
ace.Selection.prototype.selectToPosition = function(pos) {
this.selectToPosition = function(pos) {
this._moveSelection(function() {
this.moveCursorToPosition(pos);
});
};
};
ace.Selection.prototype.selectUp = function() {
this.selectUp = function() {
this._moveSelection(this.moveCursorUp);
};
};
ace.Selection.prototype.selectDown = function() {
this.selectDown = function() {
this._moveSelection(this.moveCursorDown);
};
};
ace.Selection.prototype.selectRight = function() {
this.selectRight = function() {
this._moveSelection(this.moveCursorRight);
};
};
ace.Selection.prototype.selectLeft = function() {
this.selectLeft = function() {
this._moveSelection(this.moveCursorLeft);
};
};
ace.Selection.prototype.selectLineStart = function() {
this.selectLineStart = function() {
this._moveSelection(this.moveCursorLineStart);
};
};
ace.Selection.prototype.selectLineEnd = function() {
this.selectLineEnd = function() {
this._moveSelection(this.moveCursorLineEnd);
};
};
ace.Selection.prototype.selectPageDown = function() {
this.selectPageDown = function() {
var row = this.getPageDownRow() + Math.floor(this.getVisibleRowCount() / 2);
this.scrollPageDown();
@ -158,9 +161,9 @@ ace.Selection.prototype.selectPageDown = function() {
this._moveSelection(function() {
this.moveCursorTo(row, this.selectionLead.column);
});
};
};
ace.Selection.prototype.selectPageUp = function() {
this.selectPageUp = function() {
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
@ -169,28 +172,28 @@ ace.Selection.prototype.selectPageUp = function() {
this._moveSelection(function() {
this.moveCursorTo(row, this.selectionLead.column);
});
};
};
ace.Selection.prototype.selectFileEnd = function() {
this.selectFileEnd = function() {
this._moveSelection(this.moveCursorFileEnd);
};
};
ace.Selection.prototype.selectFileStart = function() {
this.selectFileStart = function() {
this._moveSelection(this.moveCursorFileStart);
};
};
ace.Selection.prototype.tokenRe = /^[\w\d]+/g;
ace.Selection.prototype.nonTokenRe = /^[^\w\d]+/g;
this.tokenRe = /^[\w\d]+/g;
this.nonTokenRe = /^[^\w\d]+/g;
ace.Selection.prototype.selectWordRight = function() {
this.selectWordRight = function() {
this._moveSelection(this.moveCursorWordRight);
};
};
ace.Selection.prototype.selectWordLeft = function() {
this.selectWordLeft = function() {
this._moveSelection(this.moveCursorWordLeft);
};
};
ace.Selection.prototype.selectWord = function() {
this.selectWord = function() {
var cursor = this.selectionLead;
var line = this.doc.getLine(cursor.row);
@ -225,24 +228,24 @@ ace.Selection.prototype.selectWord = function() {
this._moveSelection(function() {
this.moveCursorTo(cursor.row, end);
});
};
};
ace.Selection.prototype.selectLine = function() {
this.selectLine = function() {
this.setSelectionAnchor(this.selectionLead.row, 0);
this._moveSelection(function() {
this.moveCursorTo(this.selectionLead.row + 1, 0);
});
};
};
ace.Selection.prototype.moveCursorUp = function() {
this.moveCursorUp = function() {
this.moveCursorBy(-1, 0);
};
};
ace.Selection.prototype.moveCursorDown = function() {
this.moveCursorDown = function() {
this.moveCursorBy(1, 0);
};
};
ace.Selection.prototype.moveCursorLeft = function() {
this.moveCursorLeft = function() {
if (this.selectionLead.column == 0) {
if (this.selectionLead.row > 0) {
this.moveCursorTo(this.selectionLead.row - 1, this.doc
@ -252,9 +255,9 @@ ace.Selection.prototype.moveCursorLeft = function() {
else {
this.moveCursorBy(0, -1);
}
};
};
ace.Selection.prototype.moveCursorRight = function() {
this.moveCursorRight = function() {
if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
if (this.selectionLead.row < this.doc.getLength() - 1) {
this.moveCursorTo(this.selectionLead.row + 1, 0);
@ -263,28 +266,28 @@ ace.Selection.prototype.moveCursorRight = function() {
else {
this.moveCursorBy(0, 1);
}
};
};
ace.Selection.prototype.moveCursorLineStart = function() {
this.moveCursorLineStart = function() {
this.moveCursorTo(this.selectionLead.row, 0);
};
};
ace.Selection.prototype.moveCursorLineEnd = function() {
this.moveCursorLineEnd = function() {
this.moveCursorTo(this.selectionLead.row,
this.doc.getLine(this.selectionLead.row).length);
};
};
ace.Selection.prototype.moveCursorFileEnd = function() {
this.moveCursorFileEnd = function() {
var row = this.doc.getLength() - 1;
var column = this.doc.getLine(row).length;
this.moveCursorTo(row, column);
};
};
ace.Selection.prototype.moveCursorFileStart = function() {
this.moveCursorFileStart = function() {
this.moveCursorTo(0, 0);
};
};
ace.Selection.prototype.moveCursorWordRight = function() {
this.moveCursorWordRight = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var line = this.doc.getLine(row);
@ -308,9 +311,9 @@ ace.Selection.prototype.moveCursorWordRight = function() {
}
this.moveCursorTo(row, column);
};
};
ace.Selection.prototype.moveCursorWordLeft = function() {
this.moveCursorWordLeft = function() {
var row = this.selectionLead.row;
var column = this.selectionLead.column;
var line = this.doc.getLine(row);
@ -334,27 +337,27 @@ ace.Selection.prototype.moveCursorWordLeft = function() {
}
this.moveCursorTo(row, column);
};
};
ace.Selection.prototype.moveCursorBy = function(rows, chars) {
this.moveCursorBy = function(rows, chars) {
this.moveCursorTo(this.selectionLead.row + rows, this.selectionLead.column + chars);
};
};
ace.Selection.prototype.moveCursorToPosition = function(position) {
this.moveCursorToPosition = function(position) {
this.moveCursorTo(position.row, position.column);
};
};
ace.Selection.prototype.moveCursorTo = function(row, column) {
this.moveCursorTo = function(row, column) {
this.selectionLead = this._clipPositionToDocument(row, column);
this.updateCursor();
};
};
ace.Selection.prototype.moveCursorUp = function() {
this.moveCursorUp = function() {
this.moveCursorBy(-1, 0);
};
};
ace.Selection.prototype._clipPositionToDocument = function(row, column) {
this._clipPositionToDocument = function(row, column) {
var pos = {};
if (row >= this.doc.getLength()) {
@ -371,11 +374,13 @@ ace.Selection.prototype._clipPositionToDocument = function(row, column) {
Math.max(0, column));
}
return pos;
};
};
ace.Selection.prototype._clone = function(pos) {
this._clone = function(pos) {
return {
row: pos.row,
column: pos.column
};
};
};
}).call(ace.Selection.prototype);

View file

@ -17,7 +17,9 @@ ace.Tokenizer = function(rules) {
}
};
ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
(function() {
this.getLineTokens = function(line, startState) {
var currentState = startState;
var state = this.rules[currentState];
var re = this.regExps[currentState];
@ -85,4 +87,6 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
tokens : tokens,
state : currentState
};
};
};
}).call(ace.Tokenizer.prototype);

View file

@ -38,35 +38,37 @@ ace.VirtualRenderer = function(container) {
this.onResize();
};
ace.VirtualRenderer.prototype.setDocument = function(doc) {
(function() {
this.setDocument = function(doc) {
this.lines = doc.lines;
this.doc = doc;
this.markerLayer.setDocument(doc);
this.textLayer.setTabSize(doc.getTabSize());
};
};
ace.VirtualRenderer.prototype.setTokenizer = function(tokenizer) {
this.setTokenizer = function(tokenizer) {
this.textLayer.setTokenizer(tokenizer);
};
};
ace.VirtualRenderer.prototype.getContainerElement = function() {
this.getContainerElement = function() {
return this.container;
};
};
ace.VirtualRenderer.prototype.getMouseEventTarget = function() {
this.getMouseEventTarget = function() {
return this.scroller;
};
};
ace.VirtualRenderer.prototype.getFirstVisibleRow = function() {
this.getFirstVisibleRow = function() {
return this.layerConfig.firstRow || 0;
};
};
ace.VirtualRenderer.prototype.getLastVisibleRow = function() {
this.getLastVisibleRow = function() {
return this.layerConfig.lastRow || 0;
};
};
ace.VirtualRenderer.prototype.onResize = function()
{
this.onResize = function()
{
var height = ace.getInnerHeight(this.container);
this.gutter.style.height = height + "px";
this.scroller.style.height = height + "px";
@ -82,18 +84,18 @@ ace.VirtualRenderer.prototype.onResize = function()
this.scrollToY(this.getScrollTop());
this.draw();
}
};
};
ace.VirtualRenderer.prototype.onScroll = function(e) {
this.onScroll = function(e) {
this.scrollToY(e.data);
};
};
ace.VirtualRenderer.prototype._updateScrollBar = function() {
this._updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight);
this.scrollBar.setScrollTop(this.scrollTop);
};
};
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
this.updateLines = function(firstRow, lastRow) {
var layerConfig = this.layerConfig;
if (firstRow > layerConfig.lastRow + 1) { return; }
@ -107,9 +109,9 @@ ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
// else update only the changed rows
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
};
};
ace.VirtualRenderer.prototype.draw = function() {
this.draw = function() {
var lines = this.lines;
var offset = this.scrollTop % this.lineHeight;
@ -145,30 +147,30 @@ ace.VirtualRenderer.prototype.draw = function() {
this.gutterLayer.update(layerConfig);
this._updateScrollBar();
};
};
ace.VirtualRenderer.prototype.addMarker = function(range, clazz, type) {
this.addMarker = function(range, clazz, type) {
return this.markerLayer.addMarker(range, clazz, type);
};
};
ace.VirtualRenderer.prototype.removeMarker = function(markerId) {
this.removeMarker = function(markerId) {
this.markerLayer.removeMarker(markerId);
};
};
ace.VirtualRenderer.prototype.updateCursor = function(position) {
this.updateCursor = function(position) {
this.cursorLayer.setCursor(position);
this.cursorLayer.update(this.layerConfig);
};
};
ace.VirtualRenderer.prototype.hideCursor = function() {
this.hideCursor = function() {
this.cursorLayer.hideCursor();
};
};
ace.VirtualRenderer.prototype.showCursor = function() {
this.showCursor = function() {
this.cursorLayer.showCursor();
};
};
ace.VirtualRenderer.prototype.scrollCursorIntoView = function() {
this.scrollCursorIntoView = function() {
var pos = this.cursorLayer.getPixelPosition();
var left = pos.left;
@ -192,21 +194,21 @@ ace.VirtualRenderer.prototype.scrollCursorIntoView = function() {
this.scroller.scrollLeft = Math.round(left + this.characterWidth
- this.scroller.clientWidth);
}
},
},
ace.VirtualRenderer.prototype.getScrollTop = function() {
this.getScrollTop = function() {
return this.scrollTop;
};
};
ace.VirtualRenderer.prototype.getScrollTopRow = function() {
this.getScrollTopRow = function() {
return this.scrollTop / this.lineHeight;
};
};
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToRow = function(row) {
this.scrollToY(row * this.lineHeight);
};
};
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) {
this.scrollToY = function(scrollTop) {
var maxHeight = this.lines.length * this.lineHeight
- this.scroller.clientHeight;
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
@ -216,9 +218,9 @@ ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) {
this._updateScrollBar();
this.draw();
}
};
};
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left)
@ -230,21 +232,23 @@ ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
row : row,
column : col
};
};
};
ace.VirtualRenderer.prototype.visualizeFocus = function() {
this.visualizeFocus = function() {
ace.addCssClass(this.container, "focus");
};
};
ace.VirtualRenderer.prototype.visualizeBlur = function() {
this.visualizeBlur = function() {
ace.removeCssClass(this.container, "focus");
};
};
ace.VirtualRenderer.prototype.showComposition = function(position) {
};
this.showComposition = function(position) {
};
ace.VirtualRenderer.prototype.setCompositionText = function(text) {
};
this.setCompositionText = function(text) {
};
ace.VirtualRenderer.prototype.hideComposition = function() {
};
this.hideComposition = function() {
};
}).call(ace.VirtualRenderer.prototype);

View file

@ -11,31 +11,33 @@ ace.layer.Cursor = function(parentEl) {
this.isVisible = false;
};
ace.layer.Cursor.prototype.setCursor = function(position) {
(function() {
this.setCursor = function(position) {
this.position = {
row : position.row,
column : position.column
};
};
};
ace.layer.Cursor.prototype.hideCursor = function() {
this.hideCursor = function() {
this.isVisible = false;
if (this.cursor.parentNode) {
this.cursor.parentNode.removeChild(this.cursor);
}
clearInterval(this.blinkId);
};
};
ace.layer.Cursor.prototype.showCursor = function() {
this.showCursor = function() {
this.isVisible = true;
this.element.appendChild(this.cursor);
var cursor = this.cursor;
cursor.style.visibility = "visible";
this.restartTimer();
};
};
ace.layer.Cursor.prototype.restartTimer = function() {
this.restartTimer = function() {
clearInterval(this.blinkId);
if (!this.isVisible) {
return;
@ -48,16 +50,16 @@ ace.layer.Cursor.prototype.restartTimer = function() {
cursor.style.visibility = "visible";
}, 400);
}, 1000);
};
};
ace.layer.Cursor.prototype.getPixelPosition = function() {
this.getPixelPosition = function() {
return this.pixelPos || {
left : 0,
top : 0
};
};
};
ace.layer.Cursor.prototype.update = function(config) {
this.update = function(config) {
if (!this.position)
return;
@ -78,4 +80,6 @@ ace.layer.Cursor.prototype.update = function(config) {
this.element.appendChild(this.cursor);
}
this.restartTimer();
};
};
}).call(ace.layer.Cursor.prototype);

View file

@ -6,7 +6,9 @@ ace.layer.Gutter = function(parentEl) {
parentEl.appendChild(this.element);
};
ace.layer.Gutter.prototype.update = function(config) {
(function() {
this.update = function(config) {
var html = [];
for ( var i = config.firstRow; i <= config.lastRow; i++) {
html.push("<div class='gutter-cell' style='height:" + config.lineHeight
@ -15,4 +17,6 @@ ace.layer.Gutter.prototype.update = function(config) {
}
this.element.innerHTML = html.join("");
};
};
}).call(ace.layer.Gutter.prototype);

View file

@ -9,11 +9,13 @@ ace.layer.Marker = function(parentEl) {
this._markerId = 1;
};
ace.layer.Marker.prototype.setDocument = function(doc) {
this.doc = doc;
};
(function() {
ace.layer.Marker.prototype.addMarker = function(range, clazz, type) {
this.setDocument = function(doc) {
this.doc = doc;
};
this.addMarker = function(range, clazz, type) {
var id = this._markerId++;
this.markers[id] = {
range : range,
@ -23,17 +25,17 @@ ace.layer.Marker.prototype.addMarker = function(range, clazz, type) {
this.update();
return id;
};
};
ace.layer.Marker.prototype.removeMarker = function(markerId) {
this.removeMarker = function(markerId) {
var marker = this.markers[markerId];
if (marker) {
delete (this.markers[markerId]);
this.update();
}
};
};
ace.layer.Marker.prototype.update = function(config) {
this.update = function(config) {
var config = config || this.config;
if (!config)
return;
@ -78,9 +80,9 @@ ace.layer.Marker.prototype.update = function(config) {
}
}
this.element.innerHTML = html.join("");
};
};
ace.layer.Marker.prototype.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
// selection start
var row = range.start.row;
@ -106,9 +108,9 @@ ace.layer.Marker.prototype.drawTextMarker = function(stringBuilder, range, clazz
lineRange.end.column = this.doc.getLine(row).length;
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig);
}
};
};
ace.layer.Marker.prototype.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig) {
this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig) {
var height = layerConfig.lineHeight;
var width = Math.round(layerConfig.width - (range.start.column * layerConfig.characterWidth));
@ -142,9 +144,9 @@ ace.layer.Marker.prototype.drawMultiLineMarker = function(stringBuilder, range,
"top:", top, "px;'></div>"
);
}
};
};
ace.layer.Marker.prototype.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig) {
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig) {
var height = layerConfig.lineHeight;
var width = Math.round((range.end.column - range.start.column) * layerConfig.characterWidth);
@ -158,4 +160,6 @@ ace.layer.Marker.prototype.drawSingleLineMarker = function(stringBuilder, range,
"top:", top, "px;",
"left:", left,"px;'></div>"
);
};
};
}).call(ace.layer.Marker.prototype);

View file

@ -9,19 +9,21 @@ ace.layer.Text = function(parentEl) {
this._tabString = " ";
};
ace.layer.Text.prototype.setTokenizer = function(tokenizer) {
(function() {
this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer;
};
};
ace.layer.Text.prototype.getLineHeight = function() {
this.getLineHeight = function() {
return this.lineHeight;
};
};
ace.layer.Text.prototype.getCharacterWidth = function() {
this.getCharacterWidth = function() {
return this.characterWidth;
};
};
ace.layer.Text.prototype._measureSizes = function() {
this._measureSizes = function() {
var measureNode = document.createElement("div");
var style = measureNode.style;
style.width = style.height = "auto";
@ -40,13 +42,13 @@ ace.layer.Text.prototype._measureSizes = function() {
this.characterWidth = measureNode.offsetWidth / 2000;
this.element.removeChild(measureNode);
};
};
ace.layer.Text.prototype.setTabSize = function(tabSize) {
this.setTabSize = function(tabSize) {
this._tabString = new Array(tabSize+1).join("&nbsp;");
};
};
ace.layer.Text.prototype.updateLines = function(layerConfig, firstRow, lastRow) {
this.updateLines = function(layerConfig, firstRow, lastRow) {
var first = Math.max(firstRow, layerConfig.firstRow);
var last = Math.min(lastRow, layerConfig.lastRow);
@ -59,9 +61,9 @@ ace.layer.Text.prototype.updateLines = function(layerConfig, firstRow, lastRow)
var lineElement = lineElements[i - layerConfig.firstRow];
lineElement.innerHTML = html.join("");
};
};
};
ace.layer.Text.prototype.update = function(config) {
this.update = function(config) {
var html = [];
for ( var i = config.firstRow; i <= config.lastRow; i++) {
html.push("<div class='line' style='height:" + this.lineHeight + "px;", "width:",
@ -70,9 +72,9 @@ ace.layer.Text.prototype.update = function(config) {
}
this.element.innerHTML = html.join("");
};
};
ace.layer.Text.prototype.renderLine = function(stringBuilder, row) {
this.renderLine = function(stringBuilder, row) {
var tokens = this.tokenizer.getTokens(row);
for ( var i = 0; i < tokens.length; i++) {
var token = tokens[i];
@ -80,6 +82,7 @@ ace.layer.Text.prototype.renderLine = function(stringBuilder, row) {
var output = token.value
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
//.replace(/\t/g, "&#x2023; ")
.replace(/\t/g, this._tabString)
.replace(/\s/g, "&nbsp;");
@ -91,4 +94,8 @@ ace.layer.Text.prototype.renderLine = function(stringBuilder, row) {
stringBuilder.push(output);
}
};
};
// TODO: show invisibles
//stringBuilder.push("&para;");
};
}).call(ace.layer.Text.prototype);

View file

@ -5,7 +5,9 @@ ace.mode.Css = function() {
};
ace.inherits(ace.mode.Css, ace.mode.Text);
ace.mode.Css.prototype.getNextLineIndent = function(line, state, tab) {
(function() {
this.getNextLineIndent = function(line, state, tab) {
var indent = this.$getIndent(line);
// ignore braces in comments
@ -20,4 +22,6 @@ ace.mode.Css.prototype.getNextLineIndent = function(line, state, tab) {
}
return indent;
};
};
}).call(ace.mode.Css.prototype);

View file

@ -175,6 +175,10 @@ ace.mode.CssHighlightRules = function() {
};
};
ace.mode.CssHighlightRules.prototype.getRules = function() {
(function() {
this.getRules = function() {
return this._rules;
};
};
}).call(ace.mode.CssHighlightRules.prototype);

View file

@ -8,7 +8,9 @@ ace.mode.Html = function() {
};
ace.inherits(ace.mode.Html, ace.mode.Text);
ace.mode.Html.prototype.toggleCommentLines = function(doc, range, state) {
(function() {
this.toggleCommentLines = function(doc, range, state) {
var split = state.split("js-");
if (!split[0] && split[1]) {
return this._js.toggleCommentLines(doc, range, state);
@ -20,9 +22,9 @@ ace.mode.Html.prototype.toggleCommentLines = function(doc, range, state) {
}
return 0;
};
};
ace.mode.Html.prototype.getNextLineIndent = function(line, state, tab) {
this.getNextLineIndent = function(line, state, tab) {
var split = state.split("js-");
if (!split[0] && split[1]) {
return this._js.getNextLineIndent(line, split[1], tab);
@ -34,4 +36,6 @@ ace.mode.Html.prototype.getNextLineIndent = function(line, state, tab) {
}
return "";
};
};
}).call(ace.mode.Html.prototype);

View file

@ -130,8 +130,9 @@ ace.mode.HtmlHighlightRules = function() {
});
};
(function() {
ace.mode.HtmlHighlightRules.prototype._addRules = function(rules, prefix) {
this._addRules = function(rules, prefix) {
for (var key in rules) {
var state = rules[key];
for (var i=0; i<state.length; i++) {
@ -142,8 +143,10 @@ ace.mode.HtmlHighlightRules.prototype._addRules = function(rules, prefix) {
}
this._rules[prefix + key] = state;
}
};
};
ace.mode.HtmlHighlightRules.prototype.getRules = function() {
this.getRules = function() {
return this._rules;
};
};
}).call(ace.mode.HtmlHighlightRules.prototype);

View file

@ -5,15 +5,17 @@ ace.mode.JavaScript = function() {
};
ace.inherits(ace.mode.JavaScript, ace.mode.Text);
ace.mode.JavaScript.prototype.toggleCommentLines = function(doc, range, state) {
(function() {
this.toggleCommentLines = function(doc, range, state) {
var addedRows = doc.outdentRows(range, "//");
if (addedRows == 0) {
var addedRows = doc.indentRows(range, "//");
};
return addedRows;
};
};
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
this.getNextLineIndent = function(line, state, tab) {
var indent = this.$getIndent(line);
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
@ -43,4 +45,6 @@ ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
}
return indent;
};
};
}).call(ace.mode.JavaScript.prototype);

View file

@ -127,6 +127,10 @@ ace.mode.JavaScriptHighlightRules = function() {
};
};
ace.mode.JavaScriptHighlightRules.prototype.getRules = function() {
(function() {
this.getRules = function() {
return this._rules;
};
};
}).call(ace.mode.JavaScriptHighlightRules.prototype);

View file

@ -10,23 +10,27 @@ ace.mode.Text = function() {
this.$tokenizer = new ace.Tokenizer(rules);
};
ace.mode.Text.prototype.getTokenizer = function() {
(function() {
this.getTokenizer = function() {
return this.$tokenizer;
};
};
ace.mode.Text.prototype.toggleCommentLines = function(doc, range, state) {
this.toggleCommentLines = function(doc, range, state) {
return 0;
};
};
ace.mode.Text.prototype.getNextLineIndent = function(line, state, tab) {
this.getNextLineIndent = function(line, state, tab) {
return "";
};
};
ace.mode.Text.prototype.$getIndent = function(line) {
this.$getIndent = function(line) {
var match = line.match(/^(\s+)/);
if (match) {
return match[1];
}
return "";
};
};
}).call(ace.mode.Text.prototype);

View file

@ -70,6 +70,10 @@ ace.mode.XmlHighlightRules = function() {
};
};
ace.mode.XmlHighlightRules.prototype.getRules = function() {
(function() {
this.getRules = function() {
return this._rules;
};
};
}).call(ace.mode.XmlHighlightRules.prototype);