diff --git a/dist/ot-min.js b/dist/ot-min.js index 635fd95..7b442eb 100644 --- a/dist/ot-min.js +++ b/dist/ot-min.js @@ -8,4 +8,4 @@ */ -if(void 0===ot)var ot={};if(ot.TextOperation=function(){"use strict";function a(){if(!this||this.constructor!==a)return new a;this.ops=[],this.baseLength=0,this.targetLength=0}function b(b,c){var d=b.ops,e=a.isRetain;switch(d.length){case 1:return d[0];case 2:return e(d[0])?d[1]:e(d[1])?d[0]:null;case 3:if(e(d[0])&&e(d[2]))return d[1]}return null}function c(a){return d(a.ops[0])?a.ops[0]:0}a.prototype.equals=function(a){if(this.baseLength!==a.baseLength)return!1;if(this.targetLength!==a.targetLength)return!1;if(this.ops.length!==a.ops.length)return!1;for(var b=0;b0},e=a.isInsert=function(a){return"string"==typeof a},f=a.isDelete=function(a){return"number"==typeof a&&a<0};return a.prototype.retain=function(a){if("number"!=typeof a)throw new Error("retain expects an integer");return 0===a?this:(this.baseLength+=a,this.targetLength+=a,d(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=a:this.ops.push(a),this)},a.prototype.insert=function(a){if("string"!=typeof a)throw new Error("insert expects a string");if(""===a)return this;this.targetLength+=a.length;var b=this.ops;return e(b[b.length-1])?b[b.length-1]+=a:f(b[b.length-1])?e(b[b.length-2])?b[b.length-2]+=a:(b[b.length]=b[b.length-1],b[b.length-2]=a):b.push(a),this},a.prototype.delete=function(a){if("string"==typeof a&&(a=a.length),"number"!=typeof a)throw new Error("delete expects an integer or a string");return 0===a?this:(a>0&&(a=-a),this.baseLength-=a,f(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=a:this.ops.push(a),this)},a.prototype.isNoop=function(){return 0===this.ops.length||1===this.ops.length&&d(this.ops[0])},a.prototype.toString=function(){return(Array.prototype.map||function(a){for(var b=this,c=[],d=0,e=b.length;da.length)throw new Error("Operation can't retain more characters than are left in the string.");c[f++]=a.slice(g,g+k),g+=k}else e(k)?c[f++]=k:g-=k}if(g!==a.length)throw new Error("The operation didn't operate on the whole string.");return c.join("")},a.prototype.invert=function(b){for(var c=0,f=new a,g=this.ops,h=0,i=g.length;hm?(g.retain(m),l-=m,m=i[k++]):l===m?(g.retain(l),l=h[j++],m=i[k++]):(g.retain(l),m-=l,l=h[j++]);else if(e(l)&&f(m))l.length>-m?(l=l.slice(-m),m=i[k++]):l.length===-m?(l=h[j++],m=i[k++]):(m+=l.length,l=h[j++]);else if(e(l)&&d(m))l.length>m?(g.insert(l.slice(0,m)),l=l.slice(m),m=i[k++]):l.length===m?(g.insert(l),l=h[j++],m=i[k++]):(g.insert(l),m-=l.length,l=h[j++]);else{if(!d(l)||!f(m))throw new Error("This shouldn't happen: op1: "+JSON.stringify(l)+", op2: "+JSON.stringify(m));l>-m?(g.delete(m),l+=m,m=i[k++]):l===-m?(g.delete(m),l=h[j++],m=i[k++]):(g.delete(l),m+=l,l=h[j++])}}}return g},a.prototype.shouldBeComposedWith=function(a){if(this.isNoop()||a.isNoop())return!0;var d=c(this),g=c(a),h=b(this),i=b(a);return!(!h||!i)&&(e(h)&&e(i)?d+h.length===g:!(!f(h)||!f(i))&&(g-i===d||d===g))},a.prototype.shouldBeComposedWithInverted=function(a){if(this.isNoop()||a.isNoop())return!0;var d=c(this),g=c(a),h=b(this),i=b(a);return!(!h||!i)&&(e(h)&&e(i)?d+h.length===g||d===g:!(!f(h)||!f(i))&&g-i===d)},a.transform=function(b,c){if(b.baseLength!==c.baseLength)throw new Error("Both operations have to have the same base length");for(var g=new a,h=new a,i=b.ops,j=c.ops,k=0,l=0,m=i[k++],n=j[l++];;){if(void 0===m&&void 0===n)break;if(e(m))g.insert(m),h.retain(m.length),m=i[k++];else if(e(n))g.retain(n.length),h.insert(n),n=j[l++];else{if(void 0===m)throw new Error("Cannot compose operations: first operation is too short.");if(void 0===n)throw new Error("Cannot compose operations: first operation is too long.");var o;if(d(m)&&d(n))m>n?(o=n,m-=n,n=j[l++]):m===n?(o=n,m=i[k++],n=j[l++]):(o=m,n-=m,m=i[k++]),g.retain(o),h.retain(o);else if(f(m)&&f(n))-m>-n?(m-=n,n=j[l++]):m===n?(m=i[k++],n=j[l++]):(n-=m,m=i[k++]);else if(f(m)&&d(n))-m>n?(o=n,m+=n,n=j[l++]):-m===n?(o=n,m=i[k++],n=j[l++]):(o=-m,n+=m,m=i[k++]),g.delete(o);else{if(!d(m)||!f(n))throw new Error("The two operations aren't compatible");m>-n?(o=-n,m+=n,n=j[l++]):m===-n?(o=m,m=i[k++],n=j[l++]):(o=m,n+=m,m=i[k++]),h.delete(o)}}}return[g,h]},a}(),"object"==typeof module&&(module.exports=ot.TextOperation),void 0===ot)var ot={};if(ot.Selection=function(a){"use strict";function b(a,b){this.anchor=a,this.head=b}function c(a){this.ranges=a||[]}var d=a.ot?a.ot.TextOperation:require("./text-operation");return b.fromJSON=function(a){return new b(a.anchor,a.head)},b.prototype.equals=function(a){return this.anchor===a.anchor&&this.head===a.head},b.prototype.isEmpty=function(){return this.anchor===this.head},b.prototype.transform=function(a){function c(b){for(var c=b,e=a.ops,f=0,g=a.ops.length;f=0;e--){var f=d.transform(a[e],b);"function"==typeof f[0].isNoop&&f[0].isNoop()||c.push(f[0]),b=f[1]}return c.reverse()}var c="normal";return a.prototype.add=function(a,b){if("undoing"===this.state)this.redoStack.push(a),this.dontCompose=!0;else if("redoing"===this.state)this.undoStack.push(a),this.dontCompose=!0;else{var c=this.undoStack;!this.dontCompose&&b&&c.length>0?c.push(a.compose(c.pop())):(c.push(a),c.length>this.maxItems&&c.shift()),this.dontCompose=!1,this.redoStack=[]}},a.prototype.transform=function(a){this.undoStack=b(this.undoStack,a),this.redoStack=b(this.redoStack,a)},a.prototype.performUndo=function(a){if(this.state="undoing",0===this.undoStack.length)throw new Error("undo not possible");a(this.undoStack.pop()),this.state=c},a.prototype.performRedo=function(a){if(this.state="redoing",0===this.redoStack.length)throw new Error("redo not possible");a(this.redoStack.pop()),this.state=c},a.prototype.canUndo=function(){return 0!==this.undoStack.length},a.prototype.canRedo=function(){return 0!==this.redoStack.length},a.prototype.isUndoing=function(){return"undoing"===this.state},a.prototype.isRedoing=function(){return"redoing"===this.state},a}(),"object"==typeof module&&(module.exports=ot.UndoManager),void 0===ot)var ot={};ot.Client=function(a){"use strict";function b(a){this.revision=a,this.setState(h)}function c(){}function d(a){this.outstanding=a}function e(a,b){this.outstanding=a,this.buffer=b}function f(a,b,c){this.acknowlaged=a,this.client=b,this.revision=c}function g(a,b,c,d){this.acknowlaged=a,this.buffer=b,this.client=c,this.revision=d}b.prototype.setState=function(a){this.state=a},b.prototype.applyClient=function(a){this.setState(this.state.applyClient(this,a))},b.prototype.applyServer=function(a,b){this.setState(this.state.applyServer(this,a,b))},b.prototype.applyOperations=function(a,b){this.setState(this.state.applyOperations(this,a,b))},b.prototype.serverAck=function(a){this.setState(this.state.serverAck(this,a))},b.prototype.serverReconnect=function(){"function"==typeof this.state.resend&&this.state.resend(this)},b.prototype.transformSelection=function(a){return this.state.transformSelection(a)},b.prototype.sendOperation=function(a,b){throw new Error("sendOperation must be defined in child class")},b.prototype.applyOperation=function(a){throw new Error("applyOperation must be defined in child class")},b.Synchronized=c,c.prototype.applyClient=function(a,b){return a.sendOperation(a.revision,b),new d(b)},c.prototype.applyServer=function(a,b,c){if(b-a.revision>1)throw new Error("Invalid revision.");return a.revision=b,a.applyOperation(c),this},c.prototype.serverAck=function(a,b){throw new Error("There is no pending operation.")},c.prototype.transformSelection=function(a){return a};var h=new c;return b.AwaitingConfirm=d,d.prototype.applyClient=function(a,b){return new e(this.outstanding,b)},d.prototype.applyServer=function(a,b,c){if(b-a.revision>1)throw new Error("Invalid revision.");a.revision=b;var e=c.constructor.transform(this.outstanding,c);return a.applyOperation(e[1]),new d(e[0])},d.prototype.serverAck=function(a,b){return b-a.revision>1?new f(this.outstanding,a,b).getOperations():(a.revision=b,h)},d.prototype.transformSelection=function(a){return a.transform(this.outstanding)},d.prototype.resend=function(a){a.sendOperation(a.revision,this.outstanding)},b.AwaitingWithBuffer=e,e.prototype.applyClient=function(a,b){var c=this.buffer.compose(b);return new e(this.outstanding,c)},e.prototype.applyServer=function(a,b,c){if(b-a.revision>1)throw new Error("Invalid revision.");a.revision=b;var d=c.constructor.transform,f=d(this.outstanding,c),g=d(this.buffer,f[1]);return a.applyOperation(g[1]),new e(f[0],g[0])},e.prototype.serverAck=function(a,b){return b-a.revision>1?new g(this.outstanding,this.buffer,a,b).getOperations():(a.revision=b,a.sendOperation(a.revision,this.buffer),new d(this.buffer))},e.prototype.transformSelection=function(a){return a.transform(this.outstanding).transform(this.buffer)},e.prototype.resend=function(a){a.sendOperation(a.revision,this.outstanding)},b.Stale=f,f.prototype.applyClient=function(a,b){return new g(this.acknowlaged,b,a,this.revision)},f.prototype.applyServer=function(a,b,c){throw new Error("Ignored server-side change.")},f.prototype.applyOperations=function(a,b,c){for(var d=this.acknowlaged.constructor.transform,e=0;eb.line?1:a.chb.ch?1:0}function d(a,b){return c(a,b)<=0}function e(a,b){return d(a,b)?a:b}function f(a,b){return d(a,b)?b:a}function g(a){return a.indexFromPos({line:a.lastLine(),ch:0})+a.getLine(a.lastLine()).length}function h(a,b){var c=a[b];a[b]=function(){c.apply(a,arguments)}}function i(a){if("#"===a[0]&&(a=a.substr(1)),3===a.length){var b=a;a="",b=/^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(b).slice(1);for(var c=0;c<3;c++)a+=b[c]+b[c]}var d=/^([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i.exec(a).slice(1);return{red:parseInt(d[0],16),green:parseInt(d[1],16),blue:parseInt(d[2],16)}}var j=ot.TextOperation,k=ot.Selection;b.prototype.detach=function(){this.cm.off("changes",this.onChanges),this.cm.off("change",this.onChange),this.cm.off("cursorActivity",this.onCursorActivity),this.cm.off("focus",this.onFocus),this.cm.off("blur",this.onBlur)},b.operationFromCodeMirrorChanges=function(a,b){function c(a){return a[a.length-1]}function e(a){if(0===a.length)return 0;for(var b=0,c=0;c=0;l--){var m=a[l];k=function(a,b){return function(f){return d(f,b.from)?a(f):d(b.to,f)?a({line:f.line+b.text.length-1-(b.to.line-b.from.line),ch:b.to.line0&&(this.majorRevision+=c.length,this.minorRevision=0);var d=a.events;if(d){for(b=0;b1&&(a-=1),6*a<1?f+6*(d-f)*a:2*a<1?d:3*a<2?f+6*(d-f)*(2/3-a):f};return e(g(a+1/3),g(a),g(a-1/3))}function g(a){for(var b=1,c=0;c0&&c.shouldBeComposedWithInverted(h(this.undoManager.undoStack).wrapped)),g=new a(this.selection,d);this.undoManager.add(new n(c,g),f),this.applyClient(b)},d.prototype.updateSelection=function(){this.selection=this.editorAdapter.getSelection()},d.prototype.onSelectionChange=function(){var a=this.selection;this.updateSelection(),a&&this.selection.equals(a)||this.sendSelection(this.selection)},d.prototype.onBlur=function(){this.selection=null,this.sendSelection(null)},d.prototype.sendSelection=function(a){this.state instanceof j.AwaitingWithBuffer||this.serverAdapter.sendSelection(a)},d.prototype.sendOperation=function(a,b){this.serverAdapter.sendOperation(a,b.toJSON(),this.selection)},d.prototype.getOperations=function(a,b){this.serverAdapter.getOperations(a,b)},d.prototype.applyOperation=function(a){this.editorAdapter.applyOperation(a),this.updateSelection(),this.undoManager.transform(new n(a,null))},d}(); \ No newline at end of file +if(void 0===ot)var ot={};if(ot.TextOperation=function(){"use strict";function t(){if(!this||this.constructor!==t)return new t;this.ops=[],this.baseLength=0,this.targetLength=0}function e(e,n){var o=e.ops,r=t.isRetain;switch(o.length){case 1:return o[0];case 2:return r(o[0])?o[1]:r(o[1])?o[0]:null;case 3:if(r(o[0])&&r(o[2]))return o[1]}return null}function n(t){return o(t.ops[0])?t.ops[0]:0}t.prototype.equals=function(t){if(this.baseLength!==t.baseLength)return!1;if(this.targetLength!==t.targetLength)return!1;if(this.ops.length!==t.ops.length)return!1;for(var e=0;e0},r=t.isInsert=function(t){return"string"==typeof t},i=t.isDelete=function(t){return"number"==typeof t&&t<0};return t.prototype.retain=function(t){if("number"!=typeof t)throw new Error("retain expects an integer");return 0===t?this:(this.baseLength+=t,this.targetLength+=t,o(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=t:this.ops.push(t),this)},t.prototype.insert=function(t){if("string"!=typeof t)throw new Error("insert expects a string");if(""===t)return this;this.targetLength+=t.length;var e=this.ops;return r(e[e.length-1])?e[e.length-1]+=t:i(e[e.length-1])?r(e[e.length-2])?e[e.length-2]+=t:(e[e.length]=e[e.length-1],e[e.length-2]=t):e.push(t),this},t.prototype.delete=function(t){if("string"==typeof t&&(t=t.length),"number"!=typeof t)throw new Error("delete expects an integer or a string");return 0===t?this:(t>0&&(t=-t),this.baseLength-=t,i(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=t:this.ops.push(t),this)},t.prototype.isNoop=function(){return 0===this.ops.length||1===this.ops.length&&o(this.ops[0])},t.prototype.toString=function(){return(Array.prototype.map||function(t){for(var e=this,n=[],o=0,r=e.length;ot.length)throw new Error("Operation can't retain more characters than are left in the string.");n[i++]=t.slice(s,s+c),s+=c}else r(c)?n[i++]=c:s-=c}if(s!==t.length)throw new Error("The operation didn't operate on the whole string.");return n.join("")},t.prototype.invert=function(e){for(var n=0,i=new t,s=this.ops,a=0,h=s.length;au?(s.retain(u),l-=u,u=h[c++]):l===u?(s.retain(l),l=a[p++],u=h[c++]):(s.retain(l),u-=l,l=a[p++]);else if(r(l)&&i(u))l.length>-u?(l=l.slice(-u),u=h[c++]):l.length===-u?(l=a[p++],u=h[c++]):(u+=l.length,l=a[p++]);else if(r(l)&&o(u))l.length>u?(s.insert(l.slice(0,u)),l=l.slice(u),u=h[c++]):l.length===u?(s.insert(l),l=a[p++],u=h[c++]):(s.insert(l),u-=l.length,l=a[p++]);else{if(!o(l)||!i(u))throw new Error("This shouldn't happen: op1: "+JSON.stringify(l)+", op2: "+JSON.stringify(u));l>-u?(s.delete(u),l+=u,u=h[c++]):l===-u?(s.delete(u),l=a[p++],u=h[c++]):(s.delete(l),u+=l,l=a[p++])}}}return s},t.prototype.shouldBeComposedWith=function(t){if(this.isNoop()||t.isNoop())return!0;var o=n(this),s=n(t),a=e(this),h=e(t);return!(!a||!h)&&(r(a)&&r(h)?o+a.length===s:!(!i(a)||!i(h))&&(s-h===o||o===s))},t.prototype.shouldBeComposedWithInverted=function(t){if(this.isNoop()||t.isNoop())return!0;var o=n(this),s=n(t),a=e(this),h=e(t);return!(!a||!h)&&(r(a)&&r(h)?o+a.length===s||o===s:!(!i(a)||!i(h))&&s-h===o)},t.transform=function(e,n){if(e.baseLength!==n.baseLength)throw new Error("Both operations have to have the same base length");for(var s=new t,a=new t,h=e.ops,p=n.ops,c=0,l=0,u=h[c++],f=p[l++];;){if(void 0===u&&void 0===f)break;if(r(u))s.insert(u),a.retain(u.length),u=h[c++];else if(r(f))s.retain(f.length),a.insert(f),f=p[l++];else{if(void 0===u)throw new Error("Cannot compose operations: first operation is too short.");if(void 0===f)throw new Error("Cannot compose operations: first operation is too long.");var g;if(o(u)&&o(f))u>f?(g=f,u-=f,f=p[l++]):u===f?(g=f,u=h[c++],f=p[l++]):(g=u,f-=u,u=h[c++]),s.retain(g),a.retain(g);else if(i(u)&&i(f))-u>-f?(u-=f,f=p[l++]):u===f?(u=h[c++],f=p[l++]):(f-=u,u=h[c++]);else if(i(u)&&o(f))-u>f?(g=f,u+=f,f=p[l++]):-u===f?(g=f,u=h[c++],f=p[l++]):(g=-u,f+=u,u=h[c++]),s.delete(g);else{if(!o(u)||!i(f))throw new Error("The two operations aren't compatible");u>-f?(g=-f,u+=f,f=p[l++]):u===-f?(g=u,u=h[c++],f=p[l++]):(g=u,f+=u,u=h[c++]),a.delete(g)}}}return[s,a]},t}(),"object"==typeof module&&(module.exports=ot.TextOperation),void 0===ot)var ot={};if(ot.Selection=function(t){"use strict";function e(t,e){this.anchor=t,this.head=e}function n(t){this.ranges=t||[]}var o=t.ot?t.ot.TextOperation:require("./text-operation");return e.fromJSON=function(t){return new e(t.anchor,t.head)},e.prototype.equals=function(t){return this.anchor===t.anchor&&this.head===t.head},e.prototype.isEmpty=function(){return this.anchor===this.head},e.prototype.transform=function(t){function n(e){for(var n=e,r=t.ops,i=0,s=t.ops.length;i=0;r--){var i=o.transform(t[r],e);"function"==typeof i[0].isNoop&&i[0].isNoop()||n.push(i[0]),e=i[1]}return n.reverse()}var n="normal";return t.prototype.add=function(t,e){if("undoing"===this.state)this.redoStack.push(t),this.dontCompose=!0;else if("redoing"===this.state)this.undoStack.push(t),this.dontCompose=!0;else{var n=this.undoStack;!this.dontCompose&&e&&n.length>0?n.push(t.compose(n.pop())):(n.push(t),n.length>this.maxItems&&n.shift()),this.dontCompose=!1,this.redoStack=[]}},t.prototype.transform=function(t){this.undoStack=e(this.undoStack,t),this.redoStack=e(this.redoStack,t)},t.prototype.performUndo=function(t){if(this.state="undoing",0===this.undoStack.length)throw new Error("undo not possible");t(this.undoStack.pop()),this.state=n},t.prototype.performRedo=function(t){if(this.state="redoing",0===this.redoStack.length)throw new Error("redo not possible");t(this.redoStack.pop()),this.state=n},t.prototype.canUndo=function(){return 0!==this.undoStack.length},t.prototype.canRedo=function(){return 0!==this.redoStack.length},t.prototype.isUndoing=function(){return"undoing"===this.state},t.prototype.isRedoing=function(){return"redoing"===this.state},t}(),"object"==typeof module&&(module.exports=ot.UndoManager),void 0===ot)var ot={};ot.Client=function(t){"use strict";function e(t){this.revision=t,this.setState(a)}function n(){}function o(t){this.outstanding=t}function r(t,e){this.outstanding=t,this.buffer=e}function i(t,e,n){this.acknowlaged=t,this.client=e,this.revision=n}function s(t,e,n,o){this.acknowlaged=t,this.buffer=e,this.client=n,this.revision=o}e.prototype.setState=function(t){this.state=t},e.prototype.applyClient=function(t){this.setState(this.state.applyClient(this,t))},e.prototype.applyServer=function(t,e){this.setState(this.state.applyServer(this,t,e))},e.prototype.applyOperations=function(t,e){this.setState(this.state.applyOperations(this,t,e))},e.prototype.serverAck=function(t){this.setState(this.state.serverAck(this,t))},e.prototype.serverReconnect=function(){"function"==typeof this.state.resend&&this.state.resend(this)},e.prototype.transformSelection=function(t){return this.state.transformSelection(t)},e.prototype.sendOperation=function(t,e){throw new Error("sendOperation must be defined in child class")},e.prototype.applyOperation=function(t){throw new Error("applyOperation must be defined in child class")},e.Synchronized=n,n.prototype.applyClient=function(t,e){return t.sendOperation(t.revision,e),new o(e)},n.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");return t.revision=e,t.applyOperation(n),this},n.prototype.serverAck=function(t,e){throw new Error("There is no pending operation.")},n.prototype.transformSelection=function(t){return t};var a=new n;return e.AwaitingConfirm=o,o.prototype.applyClient=function(t,e){return new r(this.outstanding,e)},o.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");t.revision=e;var r=n.constructor.transform(this.outstanding,n);return t.applyOperation(r[1]),new o(r[0])},o.prototype.serverAck=function(t,e){return e-t.revision>1?new i(this.outstanding,t,e).getOperations():(t.revision=e,a)},o.prototype.transformSelection=function(t){return t.transform(this.outstanding)},o.prototype.resend=function(t){t.sendOperation(t.revision,this.outstanding)},e.AwaitingWithBuffer=r,r.prototype.applyClient=function(t,e){var n=this.buffer.compose(e);return new r(this.outstanding,n)},r.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");t.revision=e;var o=n.constructor.transform,i=o(this.outstanding,n),s=o(this.buffer,i[1]);return t.applyOperation(s[1]),new r(i[0],s[0])},r.prototype.serverAck=function(t,e){return e-t.revision>1?new s(this.outstanding,this.buffer,t,e).getOperations():(t.revision=e,t.sendOperation(t.revision,this.buffer),new o(this.buffer))},r.prototype.transformSelection=function(t){return t.transform(this.outstanding).transform(this.buffer)},r.prototype.resend=function(t){t.sendOperation(t.revision,this.outstanding)},e.Stale=i,i.prototype.applyClient=function(t,e){return new s(this.acknowlaged,e,t,this.revision)},i.prototype.applyServer=function(t,e,n){throw new Error("Ignored server-side change.")},i.prototype.applyOperations=function(t,e,n){for(var o=this.acknowlaged.constructor.transform,r=0;re.line?1:t.che.ch?1:0}function o(t,e){return n(t,e)<=0}function r(t,e){return o(t,e)?t:e}function i(t,e){return o(t,e)?e:t}function s(t){return t.indexFromPos({line:t.lastLine(),ch:0})+t.getLine(t.lastLine()).length}function a(t,e){var n=t[e];t[e]=function(){n.apply(t,arguments)}}function h(t){if("#"===t[0]&&(t=t.substr(1)),3===t.length){var e=t;t="",e=/^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(e).slice(1);for(var n=0;n<3;n++)t+=e[n]+e[n]}var o=/^([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i.exec(t).slice(1);return{red:parseInt(o[0],16),green:parseInt(o[1],16),blue:parseInt(o[2],16)}}var p=ot.TextOperation,c=ot.Selection;e.prototype.detach=function(){this.cm.off("changes",this.onChanges),this.cm.off("change",this.onChange),this.cm.off("cursorActivity",this.onCursorActivity),this.cm.off("focus",this.onFocus),this.cm.off("blur",this.onBlur)},e.operationFromCodeMirrorChanges=function(t,e){function n(t){return t[t.length-1]}function r(t){if(0===t.length)return 0;for(var e=0,n=0;n=0;l--){var u=t[l],f=(c=function(t,e){return function(i){return o(i,e.from)?t(i):o(e.to,i)?t({line:i.line+e.text.length-1-(e.to.line-e.from.line),ch:e.to.line0&&(this.majorRevision+=n.length,this.minorRevision=0);var o=t.events;if(o){for(e=0;e1&&(t-=1),6*t<1?i+6*(o-i)*t:2*t<1?o:3*t<2?i+6*(o-i)*(2/3-t):i};return r(s(t+1/3),s(t),s(t-1/3))}function s(t){for(var e=1,n=0;n0&&n.shouldBeComposedWithInverted(a(this.undoManager.undoStack).wrapped)),s=new t(this.selection,o);this.undoManager.add(new f(n,s),i),this.applyClient(e)},o.prototype.updateSelection=function(){this.selection=this.editorAdapter.getSelection()},o.prototype.onSelectionChange=function(){var t=this.selection;this.updateSelection(),t&&this.selection.equals(t)||this.sendSelection(this.selection)},o.prototype.onBlur=function(){this.selection=null,this.sendSelection(null)},o.prototype.sendSelection=function(t){this.state instanceof p.AwaitingWithBuffer||this.serverAdapter.sendSelection(t)},o.prototype.sendOperation=function(t,e){this.serverAdapter.sendOperation(t,e.toJSON(),this.selection)},o.prototype.getOperations=function(t,e){this.serverAdapter.getOperations(t,e)},o.prototype.applyOperation=function(t){this.editorAdapter.applyOperation(t),this.updateSelection(),this.undoManager.transform(new f(t,null))},o}(); \ No newline at end of file diff --git a/dist/ot.js b/dist/ot.js index 07c279e..6325b91 100644 --- a/dist/ot.js +++ b/dist/ot.js @@ -1921,7 +1921,6 @@ ot.EditorClient = (function () { }; EditorClient.prototype.onClientLeft = function (clientId) { - console.log("User disconnected: " + clientId); var client = this.clients[clientId]; if (!client) { return; } client.remove(); diff --git a/lib/editor-client.js b/lib/editor-client.js index 94571ef..d2a8b33 100644 --- a/lib/editor-client.js +++ b/lib/editor-client.js @@ -224,7 +224,6 @@ ot.EditorClient = (function () { }; EditorClient.prototype.onClientLeft = function (clientId) { - console.log("User disconnected: " + clientId); var client = this.clients[clientId]; if (!client) { return; } client.remove();