From 2083cdb6b088a7940dbd65ca6b4bdb51301287ca Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@rwth-aachen.de>
Date: Fri, 1 Jul 2016 17:45:53 +0200
Subject: [PATCH] several bug-fixes (for y-richtext beta)

---
 src/Utils.js | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/Utils.js b/src/Utils.js
index e7ef0420..5c37102f 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -323,11 +323,27 @@ module.exports = function (Y /* : any*/) {
               ins.push(o)
             }
           })
+          this.waiting = []
           // put in executable order
           ins = notSoSmartSort(ins)
-          ins.forEach(this.onevent)
-          dels.forEach(this.onevent)
-          this.waiting = []
+          // this.onevent can trigger the creation of another operation
+          // -> check if this.awaiting increased & stop computation if it does
+          for (var i = 0; i < ins.length; i++) {
+            if (this.awaiting === 0) {
+              this.onevent(ins[i])
+            } else {
+              this.waiting = this.waiting.concat(ins.slice(i))
+              break
+            }
+          }
+          for (var i = 0; i < dels.length; i++) {
+            if (this.awaiting === 0) {
+              this.onevent(dels[i])
+            } else {
+              this.waiting = this.waiting.concat(dels.slice(i))
+              break
+            }
+          }
         }
       }
     }
-- 
GitLab