From fc5be5c7cc86cae916baa7c49a7f3e3f96e0b9dd Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Sun, 31 Dec 2017 14:49:20 +0100 Subject: [PATCH] fix empty string insertion bug --- src/Type/YText.js | 3 +++ src/Util/ID.js | 6 +++++- src/Util/RootID.js | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Type/YText.js b/src/Type/YText.js index 16dd9318..959b92fe 100644 --- a/src/Type/YText.js +++ b/src/Type/YText.js @@ -24,6 +24,9 @@ export default class YText extends YArray { return strBuilder.join('') } insert (pos, text) { + if (text.length <= 0) { + return + } this._transact(y => { let left = null let right = this._start diff --git a/src/Util/ID.js b/src/Util/ID.js index 3c3e8235..fc261340 100644 --- a/src/Util/ID.js +++ b/src/Util/ID.js @@ -11,6 +11,10 @@ export default class ID { return id !== null && id.user === this.user && id.clock === this.clock } lessThan (id) { - return this.user < id.user || (this.user === id.user && this.clock < id.clock) + if (id.constructor === ID) { + return this.user < id.user || (this.user === id.user && this.clock < id.clock) + } else { + return false + } } } diff --git a/src/Util/RootID.js b/src/Util/RootID.js index 0968dced..1e4610f9 100644 --- a/src/Util/RootID.js +++ b/src/Util/RootID.js @@ -12,6 +12,10 @@ export default class RootID { return id !== null && id.user === this.user && id.name === this.name && id.type === this.type } lessThan (id) { - return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type))) + if (id.constructor === RootID) { + return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type))) + } else { + return true + } } }