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

This commit is contained in:
Fabian Jakobs 2010-11-02 18:50:43 +01:00
commit 98f1ad6ab8
2 changed files with 57 additions and 44 deletions

View file

@ -557,7 +557,7 @@ var Document = function(text, mode) {
this.selection.moveCursorToPosition(delta.range.start); this.selection.moveCursorToPosition(delta.range.start);
} else { } else {
this.insert(delta.range.start, delta.text, true); this.insert(delta.range.start, delta.text, true);
this.selection.setSelectionRange(delta.range); this.selection.clearSelection();
} }
} }
}, },

View file

@ -148,10 +148,6 @@ var Editor = function(renderer, doc) {
this.renderer.setTheme(theme); this.renderer.setTheme(theme);
}; };
this.setShowGutter = function(show){
this.renderer.setShowGutter(show);
}
this.$highlightBrackets = function() { this.$highlightBrackets = function() {
if (this.$bracketHighlight) { if (this.$bracketHighlight) {
this.renderer.removeMarker(this.$bracketHighlight); this.renderer.removeMarker(this.$bracketHighlight);
@ -398,10 +394,10 @@ var Editor = function(renderer, doc) {
this.clearSelection(); this.clearSelection();
var _self = this; var _self = this;
var row = cursor.row; this.bgTokenizer.getState(cursor.row, function (lineState) {
this.bgTokenizer.getState(cursor.row-1, function (lineState) { var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(cursor.row), text);
var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(row), text); var line = _self.doc.getLine(cursor.row),
var line = _self.doc.getLine(row); lineIndent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString());
var end = _self.doc.insert(cursor, text); var end = _self.doc.insert(cursor, text);
/* TODO: This shortcut is somehow broken /* TODO: This shortcut is somehow broken
@ -412,15 +408,40 @@ var Editor = function(renderer, doc) {
} }
*/ */
var line = _self.doc.getLine(row); _self.bgTokenizer.getState(cursor.row, function(lineState) {
_self.bgTokenizer.getState(row, function(lineState) {
// multi line insert // multi line insert
if (row !== end.row) { if (cursor.row != end.row) {
var indent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString()); var size = _self.doc.getTabSize(),
if (indent) { minIndent = Number.MAX_VALUE;
var indentRange = new Range(row+1, 0, end.row, end.column);
end.column += _self.doc.indentRows(indentRange, indent); for (var row = cursor.row + 1; row <= end.row; ++row) {
var indent = 0;
line = _self.doc.getLine(row);
for (var i = 0; i < line.length; ++i)
if (line.charAt(i) == '\t')
indent += size;
else if (line.charAt(i) == ' ')
indent += 1;
else
break;
if (/[^\s]$/.test(line))
minIndent = Math.min(indent, minIndent);
} }
for (var row = cursor.row + 1; row <= end.row; ++row) {
var outdent = minIndent;
line = _self.doc.getLine(row);
for (var i = 0; i < line.length && outdent > 0; ++i)
if (line.charAt(i) == '\t')
outdent -= size;
else if (line.charAt(i) == ' ')
outdent -= 1;
_self.doc.replace(new Range(row, 0, row, line.length), line.substr(i));
}
end.column += _self.doc.indentRows(
new Range(cursor.row + 1, 0, end.row, end.column),
lineIndent);
} else { } else {
if (shouldOutdent) { if (shouldOutdent) {
end.column += _self.mode.autoOutdent(lineState, _self.doc, row); end.column += _self.mode.autoOutdent(lineState, _self.doc, row);
@ -697,23 +718,17 @@ var Editor = function(renderer, doc) {
return this.renderer.getLastVisibleRow(); return this.renderer.getLastVisibleRow();
}; };
this.getFirstFullyVisibleRow = function(){
return this.renderer.getFirstFullyVisibleRow();
}
this.getLastFullyVisibleRow = function(){
return this.renderer.getLastFullyVisibleRow();
}
this.isRowVisible = function(row) { this.isRowVisible = function(row) {
return (row >= this.getFirstFullyVisibleRow() && row <= this.getLastFullyVisibleRow()); return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
}; };
this.getVisibleRowCount = function() { this.getVisibleRowCount = function() {
return this.getLastVisibleRow() - this.getFirstVisibleRow() + 1; return this.getLastVisibleRow() - this.getFirstVisibleRow() + 1;
}; };
this.getPageDownRow = this.getLastFullyVisibleRow; this.getPageDownRow = function() {
return this.renderer.getLastVisibleRow() - 1;
};
this.getPageUpRow = function() { this.getPageUpRow = function() {
var firstRow = this.renderer.getFirstVisibleRow(); var firstRow = this.renderer.getFirstVisibleRow();
@ -746,8 +761,6 @@ var Editor = function(renderer, doc) {
}; };
this.gotoPageDown = function() { this.gotoPageDown = function() {
console.log("Goto page down");
var row = this.getPageDownRow(), var row = this.getPageDownRow(),
column = Math.min(this.getCursorPosition().column, column = Math.min(this.getCursorPosition().column,
this.doc.getLine(row).length); this.doc.getLine(row).length);
@ -757,8 +770,6 @@ var Editor = function(renderer, doc) {
}; };
this.gotoPageUp = function() { this.gotoPageUp = function() {
console.log("Goto page up");
var row = this.getPageUpRow(), var row = this.getPageUpRow(),
column = Math.min(this.getCursorPosition().column, column = Math.min(this.getCursorPosition().column,
this.doc.getLine(row).length); this.doc.getLine(row).length);
@ -804,11 +815,11 @@ var Editor = function(renderer, doc) {
}; };
this.gotoLine = function(lineNumber, column) { this.gotoLine = function(lineNumber, row) {
this.selection.clearSelection(); this.selection.clearSelection();
this.$blockScrolling = true; this.$blockScrolling = true;
this.moveCursorTo(lineNumber-1, column || 0); this.moveCursorTo(lineNumber-1, row || 0);
this.$blockScrolling = false; this.$blockScrolling = false;
if (!this.isRowVisible(this.getCursorPosition().row)) { if (!this.isRowVisible(this.getCursorPosition().row)) {
@ -902,9 +913,12 @@ var Editor = function(renderer, doc) {
}; };
this.replace = function(replacement, options) { this.replace = function(replacement, options) {
console.log("replacing with " + replacement);
if (options) if (options)
this.$search.set(options); this.$search.set(options);
var range = this.$tryReplace(this.getSelectionRange(), replacement);
var range = this.$search.find(this.doc);
this.$tryReplace(range, replacement);
if (range !== null) if (range !== null)
this.selection.setSelectionRange(range); this.selection.setSelectionRange(range);
this.$updateDesiredColumn(); this.$updateDesiredColumn();
@ -912,10 +926,8 @@ var Editor = function(renderer, doc) {
this.replaceAll = function(replacement, options) { this.replaceAll = function(replacement, options) {
if (options) { if (options) {
console.log("Find " + options.needle);
this.$search.set(options); this.$search.set(options);
} }
console.log("Replace " + replacement);
this.clearSelection(); this.clearSelection();
this.selection.moveCursorTo(0, 0); this.selection.moveCursorTo(0, 0);
@ -925,6 +937,7 @@ var Editor = function(renderer, doc) {
for (var i = ranges.length - 1; i >= 0; --i) for (var i = ranges.length - 1; i >= 0; --i)
this.$tryReplace(ranges[i], replacement); this.$tryReplace(ranges[i], replacement);
if (ranges[0] !== null)
this.selection.setSelectionRange(ranges[0]); this.selection.setSelectionRange(ranges[0]);
this.$updateDesiredColumn(); this.$updateDesiredColumn();
}, },