Last active
January 2, 2016 21:59
-
-
Save aldendaniels/8367109 to your computer and use it in GitHub Desktop.
Ace document.applyDelta function that splits 'remove' deltas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.applyDelta = function(delta) { | |
// Split large insert deltas. This is necessary because: | |
// 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. | |
if (delta.lines.length > 65000) | |
{ | |
// Get split deltas. | |
var deltas = []; | |
var fnPush = (delta.action == 'insert' ? Array.prototype.push : Array.prototype.unshift); // Fire delete actions in reverse. | |
while (delta.lines.length > 65000) | |
{ | |
// Get split deltas. | |
var lines = delta.lines.splice(0, 65000); | |
lines.push(''); | |
fnPush.apply(deltas, [{ | |
action: delta.action, | |
lines: lines, | |
range: new Range(delta.range.start.row, delta.range.start.column, | |
delta.range.start.row + 65000, 0) | |
}]); | |
// Update remaining delta. | |
delta.range.start.row += 65000; | |
delta.range.start.column = 0; | |
} | |
fnPush.apply(deltas, [delta]); | |
// Apply split deltas. | |
for (var i in deltas) | |
{ | |
applyDelta(this.$lines, deltas[i]); | |
this._emit("change", { data: deltas[i]}); | |
} | |
} | |
else | |
{ | |
applyDelta(this.$lines, delta); | |
this._emit("change", { data: delta }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment