function updateDoc(cm, from, to, newText, selUpdate, origin) {
    // Possibly split or suppress the update based on the presence
    // of read-only spans in its range.
    var split = sawReadOnlySpans &&
      removeReadOnlyRanges(cm.view.doc, from, to);
    if (split) {
      for (var i = split.length - 1; i >= 1; --i)
        updateDocInner(cm, split[i].from, split[i].to, [""], origin);
      if (split.length)
        return updateDocInner(cm, split[0].from, split[0].to, newText, selUpdate, origin);
    } else {
      return updateDocInner(cm, from, to, newText, selUpdate, origin);
    }
  }
function updateDoc(cm, from, to, newText, selUpdate, origin) {
    // Possibly split or suppress the update based on the presence
    // of read-only spans in its range.
    var split = sawReadOnlySpans &&
      removeReadOnlyRanges(cm.view.doc, from, to);
    if (split) {
      for (var i = split.length - 1; i >= 1; --i)
        updateDocInner(cm, split[i].from, split[i].to, [""], origin);
      if (split.length)
        return updateDocInner(cm, split[0].from, split[0].to, newText, selUpdate, origin);
    } else {
      return updateDocInner(cm, from, to, newText, selUpdate, origin);
    }
  }
function updateDoc ( cm , from , to , newText , selUpdate , origin ) { // Possibly split or suppress the update based on the presence // of read-only spans in its range. var split = sawReadOnlySpans && removeReadOnlyRanges ( cm . view . doc , from , to ) ; if ( split ) { for ( var i = split . length - 1 ; i >= 1 ; -- i ) updateDocInner ( cm , split [ i ] . from , split [ i ] . to , [ "" ] , origin ) ; if ( split . length ) return updateDocInner ( cm , split [ 0 ] . from , split [ 0 ] . to , newText , selUpdate , origin ) ; } else { return updateDocInner ( cm , from , to , newText , selUpdate , origin ) ; } }
Replace the range from from to to by the strings in newText. Afterwards, set the selection to selFrom, selTo.
Replace the range from from to to by the strings in newText . Afterwards set the selection to selFrom selTo .