Fixed a bug in the auto-indentation where already
existing whitespace was not taken into account.
This commit is contained in:
parent
05caccfd90
commit
37913f80a1
1 changed files with 49 additions and 29 deletions
|
|
@ -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);
|
||||
|
|
@ -393,11 +389,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
|
||||
|
|
@ -408,15 +404,45 @@ 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;
|
||||
|
||||
console.log("line indent " + lineIndent.length);
|
||||
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;
|
||||
console.log("Indent " + indent + "(" + line.length + ")");
|
||||
if (line.length != 0)
|
||||
minIndent = Math.min(indent, minIndent);
|
||||
}
|
||||
console.log("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;
|
||||
console.log("from '" + line);
|
||||
console.log("to '" + line.substr(i));
|
||||
_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);
|
||||
|
|
@ -692,24 +718,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();
|
||||
|
|
@ -800,11 +820,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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue