function rebaseHistArray(array, from, to, diff) {
  for (let i = 0; i < array.length; ++i) {
    let sub = array[i], ok = true
    if (sub.ranges) {
      if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
      for (let j = 0; j < sub.ranges.length; j++) {
        rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
        rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
      }
      continue
    }
    for (let j = 0; j < sub.changes.length; ++j) {
      let cur = sub.changes[j]
      if (to < cur.from.line) {
        cur.from = Pos(cur.from.line + diff, cur.from.ch)
        cur.to = Pos(cur.to.line + diff, cur.to.ch)
      } else if (from <= cur.to.line) {
        ok = false
        break
      }
    }
    if (!ok) {
      array.splice(0, i + 1)
      i = 0
    }
  }
}
function rebaseHistArray(array, from, to, diff) {
  for (let i = 0; i < array.length; ++i) {
    let sub = array[i], ok = true
    if (sub.ranges) {
      if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
      for (let j = 0; j < sub.ranges.length; j++) {
        rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
        rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
      }
      continue
    }
    for (let j = 0; j < sub.changes.length; ++j) {
      let cur = sub.changes[j]
      if (to < cur.from.line) {
        cur.from = Pos(cur.from.line + diff, cur.from.ch)
        cur.to = Pos(cur.to.line + diff, cur.to.ch)
      } else if (from <= cur.to.line) {
        ok = false
        break
      }
    }
    if (!ok) {
      array.splice(0, i + 1)
      i = 0
    }
  }
}
function rebaseHistArray ( array , from , to , diff ) { for ( let i = 0 ; i < array . length ; ++ i ) { let sub = array [ i ] , ok = true if ( sub . ranges ) { if ( ! sub . copied ) { sub = array [ i ] = sub . deepCopy ( ) ; sub . copied = true } for ( let j = 0 ; j < sub . ranges . length ; j ++ ) { rebaseHistSelSingle ( sub . ranges [ j ] . anchor , from , to , diff ) rebaseHistSelSingle ( sub . ranges [ j ] . head , from , to , diff ) } continue } for ( let j = 0 ; j < sub . changes . length ; ++ j ) { let cur = sub . changes [ j ] if ( to < cur . from . line ) { cur . from = Pos ( cur . from . line + diff , cur . from . ch ) cur . to = Pos ( cur . to . line + diff , cur . to . ch ) } else if ( from <= cur . to . line ) { ok = false break } } if ( ! ok ) { array . splice ( 0 , i + 1 ) i = 0 } } }
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.
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 .
rebase the history of a range