diff --git a/src/types/text-api.coffee b/src/types/text-api.coffee index 96243cef..c50c95fd 100644 --- a/src/types/text-api.coffee +++ b/src/types/text-api.coffee @@ -11,6 +11,14 @@ text.api = # Get the text contents of a document getText: -> @snapshot + setText: (text, callback) -> + cbCount = 2 + realcb = (err, result) -> + cbCount-- + callback(err, result) if callback and cbCount is 0 + @del 0, @snapshot.length, realcb + @insert 0, text, realcb + insert: (pos, text, callback) -> op = [{p:pos, i:text}] diff --git a/webclient/share.js b/webclient/share.js index daae8477..ab823c9c 100644 --- a/webclient/share.js +++ b/webclient/share.js @@ -1 +1 @@ -((function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=Array.prototype.slice,r=function(a,b){return function(){return a.apply(b,arguments)}},s=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b=0))throw new Error("position cannot be negative")},h=function(a){var b,c,d;for(c=0,d=a.length;c=c.p+c.d.length)e(a,{d:b.d,p:b.p-c.d.length});else if(b.p+b.d.length<=c.p)e(a,b);else{j={d:"",p:b.p},b.pc.p+c.d.length&&(j.d+=b.d.slice(c.p+c.d.length-b.p)),i=Math.max(b.p,c.p),g=Math.min(b.p+b.d.length,c.p+c.d.length),f=b.d.slice(i-b.p,g-b.p),k=c.d.slice(i-c.p,g-c.p);if(f!==k)throw new Error("Delete ops delete different text in the same region of the document");j.d!==""&&(j.p=o(j.p,c),e(a,j))}return a},j=function(a){return a.i!=null?{d:a.i,p:a.p}:{i:a.d,p:a.p}},m.invert=function(a){var b,c,d,e=a.slice().reverse(),f=[];for(c=0,d=e.length;c=0)){e=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,d=a.error;if(d){this.type.invert?(i=this.type.invert(e),this.pendingOp&&(p=this._xf(this.pendingOp,i),this.pendingOp=p[0],i=p[1]),this._otApply(i,!0)):this.emit("error","Op apply failed ("+d+") and the op could not be reverted"),q=this.inflightCallbacks;for(k=0,m=q.length;k=0))throw new Error("position cannot be negative")},h=function(a){var b,c,d;for(c=0,d=a.length;c=c.p+c.d.length)e(a,{d:b.d,p:b.p-c.d.length});else if(b.p+b.d.length<=c.p)e(a,b);else{j={d:"",p:b.p},b.pc.p+c.d.length&&(j.d+=b.d.slice(c.p+c.d.length-b.p)),i=Math.max(b.p,c.p),g=Math.min(b.p+b.d.length,c.p+c.d.length),f=b.d.slice(i-b.p,g-b.p),k=c.d.slice(i-c.p,g-c.p);if(f!==k)throw new Error("Delete ops delete different text in the same region of the document");j.d!==""&&(j.p=o(j.p,c),e(a,j))}return a},j=function(a){return a.i!=null?{d:a.i,p:a.p}:{i:a.d,p:a.p}},m.invert=function(a){var b,c,d,e=a.slice().reverse(),f=[];for(c=0,d=e.length;c=0)){e=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,d=a.error;if(d){this.type.invert?(i=this.type.invert(e),this.pendingOp&&(p=this._xf(this.pendingOp,i),this.pendingOp=p[0],i=p[1]),this._otApply(i,!0)):this.emit("error","Op apply failed ("+d+") and the op could not be reverted"),q=this.inflightCallbacks;for(k=0,m=q.length;k