Merge branch 'master' of github.com:ajaxorg/ace
This commit is contained in:
commit
98f1ad6ab8
2 changed files with 57 additions and 44 deletions
|
|
@ -25,7 +25,7 @@ var Document = function(text, mode) {
|
|||
if (mode) {
|
||||
this.setMode(mode);
|
||||
}
|
||||
|
||||
|
||||
if (lang.isArray(text)) {
|
||||
this.$insertLines(0, text);
|
||||
} else {
|
||||
|
|
@ -557,7 +557,7 @@ var Document = function(text, mode) {
|
|||
this.selection.moveCursorToPosition(delta.range.start);
|
||||
} else {
|
||||
this.insert(delta.range.start, delta.text, true);
|
||||
this.selection.setSelectionRange(delta.range);
|
||||
this.selection.clearSelection();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -147,11 +147,7 @@ var Editor = function(renderer, doc) {
|
|||
this.setTheme = function(theme) {
|
||||
this.renderer.setTheme(theme);
|
||||
};
|
||||
|
||||
this.setShowGutter = function(show){
|
||||
this.renderer.setShowGutter(show);
|
||||
}
|
||||
|
||||
|
||||
this.$highlightBrackets = function() {
|
||||
if (this.$bracketHighlight) {
|
||||
this.renderer.removeMarker(this.$bracketHighlight);
|
||||
|
|
@ -397,11 +393,11 @@ var Editor = function(renderer, doc) {
|
|||
|
||||
this.clearSelection();
|
||||
|
||||
var _self = this;
|
||||
var row = cursor.row;
|
||||
this.bgTokenizer.getState(cursor.row-1, function (lineState) {
|
||||
var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(row), text);
|
||||
var line = _self.doc.getLine(row);
|
||||
var _self = this;
|
||||
this.bgTokenizer.getState(cursor.row, function (lineState) {
|
||||
var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(cursor.row), text);
|
||||
var line = _self.doc.getLine(cursor.row),
|
||||
lineIndent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString());
|
||||
var end = _self.doc.insert(cursor, text);
|
||||
|
||||
/* TODO: This shortcut is somehow broken
|
||||
|
|
@ -412,15 +408,40 @@ var Editor = function(renderer, doc) {
|
|||
}
|
||||
*/
|
||||
|
||||
var line = _self.doc.getLine(row);
|
||||
_self.bgTokenizer.getState(row, function(lineState) {
|
||||
_self.bgTokenizer.getState(cursor.row, function(lineState) {
|
||||
// multi line insert
|
||||
if (row !== end.row) {
|
||||
var indent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString());
|
||||
if (indent) {
|
||||
var indentRange = new Range(row+1, 0, end.row, end.column);
|
||||
end.column += _self.doc.indentRows(indentRange, indent);
|
||||
if (cursor.row != end.row) {
|
||||
var size = _self.doc.getTabSize(),
|
||||
minIndent = Number.MAX_VALUE;
|
||||
|
||||
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 {
|
||||
if (shouldOutdent) {
|
||||
end.column += _self.mode.autoOutdent(lineState, _self.doc, row);
|
||||
|
|
@ -696,24 +717,18 @@ var Editor = function(renderer, doc) {
|
|||
this.getLastVisibleRow = function() {
|
||||
return this.renderer.getLastVisibleRow();
|
||||
};
|
||||
|
||||
this.getFirstFullyVisibleRow = function(){
|
||||
return this.renderer.getFirstFullyVisibleRow();
|
||||
}
|
||||
|
||||
this.getLastFullyVisibleRow = function(){
|
||||
return this.renderer.getLastFullyVisibleRow();
|
||||
}
|
||||
|
||||
this.isRowVisible = function(row) {
|
||||
return (row >= this.getFirstFullyVisibleRow() && row <= this.getLastFullyVisibleRow());
|
||||
return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
|
||||
};
|
||||
|
||||
this.getVisibleRowCount = function() {
|
||||
return this.getLastVisibleRow() - this.getFirstVisibleRow() + 1;
|
||||
};
|
||||
|
||||
this.getPageDownRow = this.getLastFullyVisibleRow;
|
||||
this.getPageDownRow = function() {
|
||||
return this.renderer.getLastVisibleRow() - 1;
|
||||
};
|
||||
|
||||
this.getPageUpRow = function() {
|
||||
var firstRow = this.renderer.getFirstVisibleRow();
|
||||
|
|
@ -746,8 +761,6 @@ var Editor = function(renderer, doc) {
|
|||
};
|
||||
|
||||
this.gotoPageDown = function() {
|
||||
console.log("Goto page down");
|
||||
|
||||
var row = this.getPageDownRow(),
|
||||
column = Math.min(this.getCursorPosition().column,
|
||||
this.doc.getLine(row).length);
|
||||
|
|
@ -757,8 +770,6 @@ var Editor = function(renderer, doc) {
|
|||
};
|
||||
|
||||
this.gotoPageUp = function() {
|
||||
console.log("Goto page up");
|
||||
|
||||
var row = this.getPageUpRow(),
|
||||
column = Math.min(this.getCursorPosition().column,
|
||||
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.$blockScrolling = true;
|
||||
this.moveCursorTo(lineNumber-1, column || 0);
|
||||
this.moveCursorTo(lineNumber-1, row || 0);
|
||||
this.$blockScrolling = false;
|
||||
|
||||
if (!this.isRowVisible(this.getCursorPosition().row)) {
|
||||
|
|
@ -902,20 +913,21 @@ var Editor = function(renderer, doc) {
|
|||
};
|
||||
|
||||
this.replace = function(replacement, options) {
|
||||
if (options)
|
||||
this.$search.set(options);
|
||||
var range = this.$tryReplace(this.getSelectionRange(), replacement);
|
||||
if (range !== null)
|
||||
this.selection.setSelectionRange(range);
|
||||
this.$updateDesiredColumn();
|
||||
console.log("replacing with " + replacement);
|
||||
if (options)
|
||||
this.$search.set(options);
|
||||
|
||||
var range = this.$search.find(this.doc);
|
||||
this.$tryReplace(range, replacement);
|
||||
if (range !== null)
|
||||
this.selection.setSelectionRange(range);
|
||||
this.$updateDesiredColumn();
|
||||
},
|
||||
|
||||
this.replaceAll = function(replacement, options) {
|
||||
if (options) {
|
||||
console.log("Find " + options.needle);
|
||||
this.$search.set(options);
|
||||
}
|
||||
console.log("Replace " + replacement);
|
||||
this.clearSelection();
|
||||
this.selection.moveCursorTo(0, 0);
|
||||
|
||||
|
|
@ -925,7 +937,8 @@ var Editor = function(renderer, doc) {
|
|||
|
||||
for (var i = ranges.length - 1; i >= 0; --i)
|
||||
this.$tryReplace(ranges[i], replacement);
|
||||
this.selection.setSelectionRange(ranges[0]);
|
||||
if (ranges[0] !== null)
|
||||
this.selection.setSelectionRange(ranges[0]);
|
||||
this.$updateDesiredColumn();
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue