code: function setSelection(doc, anchor, head, bias, checkAtomic) {
      if (!checkAtomic && hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) {
        var filtered = filterSelectionChange(doc, anchor, head);
        head = filtered.head;
        anchor = filtered.anchor;
      }
  
      var sel = doc.sel;
      sel.goalColumn = null;
      // Skip over atomic spans.
      if (checkAtomic || !posEq(anchor, sel.anchor))
        anchor = skipAtomic(doc, anchor, bias, checkAtomic != "push");
      if (checkAtomic || !posEq(head, sel.head))
        head = skipAtomic(doc, head, bias, checkAtomic != "push");
  
      if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
  
      sel.anchor = anchor; sel.head = head;
      var inv = posLess(head, anchor);
      sel.from = inv ? head : anchor;
      sel.to = inv ? anchor : head;
  
      if (doc.cm)
        doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged =
          doc.cm.curOp.cursorActivity = true;
  
      signalLater(doc, "cursorActivity", doc);
    }
docs: Update the selection. Last two args are only used by updateDoc, since they have to be expressed in the line numbers before the update.