           advance(elemA, lookAhead + commonPrefixLength, "A")
           advance(elemC, commonPrefixLength, "C")
         else
-          # Take as much as we can while still leaving enough to cover the
-          # remainder of deltaA
-          deltaARemaining = deltaA.endLength - docIndex
-          if deltaARemaining >= elemC.getLength()
-            take = elemC.getLength()
+          take = 1
+          if JetDelta.isInsert(elemA)
+            index = 1
+            while index < elemC.text.length
+              commonPrefixLength = 0
+              lookAhead = 0
+              while lookAhead < elemA.getLength()
+                commonPrefixLength = getCommonPrefixLength(elemA.text.substring(lookAhead), elemC.text.substring(index))
+                if commonPrefixLength != 0 then break
+                lookAhead += 1
+              if commonPrefixLength == 0
+                take++
+                index++
+              else
+                break
           else
-            take = elemC.getLength() - deltaARemaining
+            # Take as much as we can while still leaving enough to cover the
+            # remainder of deltaA
+            deltaARemaining = deltaA.endLength - docIndex
+            if deltaARemaining >= elemC.getLength()
+              take = elemC.getLength()
+            else
+              take = elemC.getLength() - deltaARemaining
           decomposed = decomposed.concat(new JetInsert(elemC.text.substr(0, take), _.clone(elemC.attributes)))
           advance(elemC, take, "C")
       else

root.JetRetain = JetRetain
root.JetInsert = JetInsert
root.JetDelta = JetDelta
root.JetSync = JetSync

          if JetInsert.isInsert(elem)
            docIndex += elem.getLength()
          else
            if elem.start <= elemC.start && elem.end > elemC.start
              take = Math.min(elemC.getLength(), elem.getLength())
              docIndex += elemC.start - elem.start
              decomposed = decomposed.concat(new JetRetain(docIndex, docIndex + take, decomposeAttributes(elem, elemC)))
              docIndex += take
              deltaA.deltas.splice(0, deltasSeen)
              advance(elem, elemC.start - elem.start + take, "A")
              advance(elemC, take, "C")
              break
            else
              docIndex += elem.getLength()
          deltasSeen++
    while (deltaC.deltas.length > 0)
      elemC = _.first(deltaC.deltas)
      console.assert(JetDelta.isInsert(elemC), "Received Retain when expecting insert: #{elemC}")
