apply arguments max length also includes actual call stack

This commit is contained in:
nightwing 2014-02-15 00:01:30 +04:00
commit 27b6d6dcd3
2 changed files with 26 additions and 21 deletions

View file

@ -302,9 +302,11 @@ var Document = function(textOrLines) {
row = 0; row = 0;
} else if (row >= length) { } else if (row >= length) {
row = length - 1; row = length - 1;
column = undefined column = undefined;
} }
var line = this.getLine(row); var line = this.getLine(row);
if (column == undefined)
column = line.length;
column = Math.min(Math.max(column, 0), line.length); column = Math.min(Math.max(column, 0), line.length);
return {row: row, column: column}; return {row: row, column: column};
}; };
@ -421,17 +423,18 @@ var Document = function(textOrLines) {
**/ **/
this.remove = function(range) { this.remove = function(range) {
var start = this.clippedPos(range.start.row, range.start.column); var start = this.clippedPos(range.start.row, range.start.column);
var end = this.clippedPos(range.end.row, range.end.column);
this.applyDelta({ this.applyDelta({
action: "remove", action: "remove",
start: start, start: start,
end: this.clippedPos(range.end.row, range.end.column), end: end,
lines: this.getLinesForRange(range), lines: this.getLinesForRange({start: start, end: end}),
}); });
return this.clonePos(start); return this.clonePos(start);
}; };
/** /**
* Removes the specified columns from the `row`. This method also triggers the `"change"` event. * Removes the specified columns from the `row`. This method also triggers a `"change"` event.
* @param {Number} row The row to remove from * @param {Number} row The row to remove from
* @param {Number} startColumn The column to start removing at * @param {Number} startColumn The column to start removing at
* @param {Number} endColumn The column to stop removing at * @param {Number} endColumn The column to stop removing at
@ -440,12 +443,13 @@ var Document = function(textOrLines) {
**/ **/
this.removeInLine = function(row, startColumn, endColumn) { this.removeInLine = function(row, startColumn, endColumn) {
var start = this.clippedPos(row, startColumn); var start = this.clippedPos(row, startColumn);
var end = this.clippedPos(row, endColumn);
this.applyDelta({ this.applyDelta({
action: "remove", action: "remove",
start: start, start: start,
end: this.clippedPos(row, endColumn), end: end,
lines: this.getLinesForRange(range), lines: this.getLinesForRange({start: start, end: end}),
}, true); }, true);
return this.clonePos(start); return this.clonePos(start);
@ -568,7 +572,7 @@ var Document = function(textOrLines) {
: !Range.comparePoints(delta.start, delta.end)) : !Range.comparePoints(delta.start, delta.end))
return; return;
if (isInsert && delta.lines.length > 0xFFFF) if (isInsert && delta.lines.length > 0xF000)
this.$splitAndapplyLargeDelta(delta); this.$splitAndapplyLargeDelta(delta);
// Apply. // Apply.
@ -579,22 +583,23 @@ var Document = function(textOrLines) {
this.$splitAndapplyLargeDelta = function(delta) { this.$splitAndapplyLargeDelta = function(delta) {
// 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(...)
// 2. fn.apply() doesn't work for a large number of params. The mallest threshold is on safari 0xFFFF. // 2. fn.apply() doesn't work for a large number of params. The smallest threshold is on safari 0xFFFF.
// we use 0xF000 to leave some space for actual stack
// //
// To Do: Ideally we'd be consistent and also split 'delete' deltas. We don't do this now, because delete // To Do: Ideally we'd be consistent and also split 'delete' deltas. We don't do this now, because delete
// delta handling is too slow. If we make delete delta handling faster we can split all large deltas // delta handling is too slow. If we make delete delta handling faster we can split all large deltas
// as shown in https://gist.github.com/aldendaniels/8367109#file-document-snippet-js // as shown in https://gist.github.com/aldendaniels/8367109#file-document-snippet-js
// If we do this, update validateDelta() to limit the number of lines in a delete delta. // If we do this, update validateDelta() to limit the number of lines in a delete delta.
while (delta.lines.length > 0xFFFF) { while (delta.lines.length > 0xF000) {
// Get split deltas. // Get split deltas.
var lines = delta.lines.splice(0, 0xFFFF); var lines = delta.lines.splice(0, 0xF000);
lines.push(""); lines.push("");
var start = delta.start; var start = delta.start;
this.applyDelta({ this.applyDelta({
action: delta.action, action: delta.action,
lines: lines, lines: lines,
start: this.pos(start.row, start.column), start: this.pos(start.row, start.column),
end: this.pos(start.row += 0xFFFF, start.column = 0) // Updates remaining delta. end: this.pos(start.row += 0xF000, start.column = 0) // Updates remaining delta.
}, true); }, true);
} }
}; };

View file

@ -150,7 +150,7 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
**/ **/
this.onUpdate = function(event) { this.onUpdate = function(event) {
var delta = event.data; var delta = event.data;
var range = delta.range; var range = delta;
if(range.start.row !== range.end.row) return; if(range.start.row !== range.end.row) return;
if(range.start.row !== this.pos.row) return; if(range.start.row !== this.pos.row) return;
if (this.$updating) return; if (this.$updating) return;