code: function rebaseHistArray(array, from, to, diff) {
      for (var i = 0; i < array.length; ++i) {
        var sub = array[i], ok = true;
        for (var j = 0; j < sub.changes.length; ++j) {
          var cur = sub.changes[j];
          if (!sub.copied) { cur.from = copyPos(cur.from); cur.to = copyPos(cur.to); }
          if (to < cur.from.line) {
            cur.from.line += diff;
            cur.to.line += diff;
          } else if (from <= cur.to.line) {
            ok = false;
            break;
          }
        }
        if (!sub.copied) {
          sub.anchorBefore = copyPos(sub.anchorBefore); sub.headBefore = copyPos(sub.headBefore);
          sub.anchorAfter = copyPos(sub.anchorAfter); sub.readAfter = copyPos(sub.headAfter);
          sub.copied = true;
        }
        if (!ok) {
          array.splice(0, i + 1);
          i = 0;
        } else {
          rebaseHistSel(sub.anchorBefore); rebaseHistSel(sub.headBefore);
          rebaseHistSel(sub.anchorAfter); rebaseHistSel(sub.headAfter);
        }
      }
    }
docs: Tries to rebase an array of history events given a change in the document. If the change touches the same lines as the event, the event, and everything 'behind' it, is discarded. If the change is before the event, the event's positions are updated. Uses a copy-on-write scheme for the positions, to avoid having to reallocate them all on every rebase, but also avoid problems with shared position objects being unsafely updated.