Add a doNotValidate param to applyDelta
Set it to true in insertInLine/removeInLine. Also sped up indent/dedent by using insertInLine and removeInLine.
This commit is contained in:
parent
ef0e8da522
commit
f59708a5ba
3 changed files with 20 additions and 19 deletions
|
|
@ -86,9 +86,10 @@ function validateDelta(docLines, delta) {
|
||||||
throwDeltaError(delta, 'delta.range must match delta lines');
|
throwDeltaError(delta, 'delta.range must match delta lines');
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.applyDelta = function(docLines, delta) {
|
exports.applyDelta = function(docLines, delta, doNotValidate) {
|
||||||
|
|
||||||
// Validate delta.
|
// Validate delta.
|
||||||
|
if (!doNotValidate)
|
||||||
validateDelta(docLines, delta);
|
validateDelta(docLines, delta);
|
||||||
|
|
||||||
// Apply delta.
|
// Apply delta.
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ var Document = function(textOrLines) {
|
||||||
action: "insert",
|
action: "insert",
|
||||||
range: Range.fromPoints(position, endPoint),
|
range: Range.fromPoints(position, endPoint),
|
||||||
lines: [text]
|
lines: [text]
|
||||||
});
|
}, true /*doNotValidate*/);
|
||||||
|
|
||||||
return endPoint;
|
return endPoint;
|
||||||
};
|
};
|
||||||
|
|
@ -449,8 +449,8 @@ var Document = function(textOrLines) {
|
||||||
this.applyDelta({
|
this.applyDelta({
|
||||||
action: 'remove',
|
action: 'remove',
|
||||||
range: range,
|
range: range,
|
||||||
lines: this.getLinesForRange(range)
|
lines: this.getLinesForRange(range),
|
||||||
});
|
}, true /*doNotValidate*/);
|
||||||
|
|
||||||
return range.start;
|
return range.start;
|
||||||
};
|
};
|
||||||
|
|
@ -567,7 +567,7 @@ var Document = function(textOrLines) {
|
||||||
* Applies `delta` to the document.
|
* Applies `delta` to the document.
|
||||||
* @param {Object} delta A delta object (can include 'insert' and 'remove' actions)
|
* @param {Object} delta A delta object (can include 'insert' and 'remove' actions)
|
||||||
**/
|
**/
|
||||||
this.applyDelta = function(delta) {
|
this.applyDelta = function(delta, doNotValidate) {
|
||||||
|
|
||||||
// Split large insert deltas. This is necessary because:
|
// Split large insert deltas. This is necessary because:
|
||||||
// 1. We need to support splicing delta lines into the document via $lines.splice.apply(...)
|
// 1. We need to support splicing delta lines into the document via $lines.splice.apply(...)
|
||||||
|
|
@ -596,7 +596,7 @@ var Document = function(textOrLines) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply.
|
// Apply.
|
||||||
applyDelta(this.$lines, delta);
|
applyDelta(this.$lines, delta, doNotValidate);
|
||||||
this._emit("change", { data: delta });
|
this._emit("change", { data: delta });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1384,7 +1384,7 @@ var EditSession = function(text, mode) {
|
||||||
this.indentRows = function(startRow, endRow, indentString) {
|
this.indentRows = function(startRow, endRow, indentString) {
|
||||||
indentString = indentString.replace(/\t/g, this.getTabString());
|
indentString = indentString.replace(/\t/g, this.getTabString());
|
||||||
for (var row=startRow; row<=endRow; row++)
|
for (var row=startRow; row<=endRow; row++)
|
||||||
this.insert({row: row, column:0}, indentString);
|
this.doc.insertInLine({row: row, column: 0}, indentString);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1395,25 +1395,25 @@ var EditSession = function(text, mode) {
|
||||||
**/
|
**/
|
||||||
this.outdentRows = function (range) {
|
this.outdentRows = function (range) {
|
||||||
var rowRange = range.collapseRows();
|
var rowRange = range.collapseRows();
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
var size = this.getTabSize();
|
var size = this.getTabSize();
|
||||||
|
|
||||||
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
|
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
|
||||||
var line = this.getLine(i);
|
var line = this.getLine(i);
|
||||||
|
var row = i;
|
||||||
|
var startCol = 0;
|
||||||
|
var endCol = 0;
|
||||||
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
for (var j = 0; j < size; ++j)
|
for (var j = 0; j < size; ++j)
|
||||||
if (line.charAt(j) != ' ')
|
if (line.charAt(j) != ' ')
|
||||||
break;
|
break;
|
||||||
if (j < size && line.charAt(j) == '\t') {
|
if (j < size && line.charAt(j) == '\t') {
|
||||||
deleteRange.start.column = j;
|
startCol = j;
|
||||||
deleteRange.end.column = j + 1;
|
endCol = j + 1;
|
||||||
} else {
|
} else {
|
||||||
deleteRange.start.column = 0;
|
startCol = 0;
|
||||||
deleteRange.end.column = j;
|
endCol = j;
|
||||||
}
|
}
|
||||||
this.remove(deleteRange);
|
this.doc.removeInLine(row, startCol, endCol);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue