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) {
|
if (mode) {
|
||||||
this.setMode(mode);
|
this.setMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lang.isArray(text)) {
|
if (lang.isArray(text)) {
|
||||||
this.$insertLines(0, text);
|
this.$insertLines(0, text);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -147,11 +147,7 @@ var Editor = function(renderer, doc) {
|
||||||
this.setTheme = function(theme) {
|
this.setTheme = function(theme) {
|
||||||
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);
|
||||||
|
|
@ -397,11 +393,11 @@ 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);
|
||||||
|
|
@ -696,24 +717,18 @@ var Editor = function(renderer, doc) {
|
||||||
this.getLastVisibleRow = function() {
|
this.getLastVisibleRow = function() {
|
||||||
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,20 +913,21 @@ var Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.replace = function(replacement, options) {
|
this.replace = function(replacement, options) {
|
||||||
if (options)
|
console.log("replacing with " + replacement);
|
||||||
this.$search.set(options);
|
if (options)
|
||||||
var range = this.$tryReplace(this.getSelectionRange(), replacement);
|
this.$search.set(options);
|
||||||
if (range !== null)
|
|
||||||
this.selection.setSelectionRange(range);
|
var range = this.$search.find(this.doc);
|
||||||
this.$updateDesiredColumn();
|
this.$tryReplace(range, replacement);
|
||||||
|
if (range !== null)
|
||||||
|
this.selection.setSelectionRange(range);
|
||||||
|
this.$updateDesiredColumn();
|
||||||
},
|
},
|
||||||
|
|
||||||
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,7 +937,8 @@ 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);
|
||||||
this.selection.setSelectionRange(ranges[0]);
|
if (ranges[0] !== null)
|
||||||
|
this.selection.setSelectionRange(ranges[0]);
|
||||||
this.$updateDesiredColumn();
|
this.$updateDesiredColumn();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue