code: function scrollCursorIntoView(cm) {
      var coords = scrollPosIntoView(cm, cm.doc.sel.head, cm.options.cursorScrollMargin);
      if (!cm.state.focused) return;
      var display = cm.display, box = getRect(display.sizer), doScroll = null, pTop = paddingTop(cm.display);
      if (coords.top + pTop + box.top < 0) doScroll = true;
      else if (coords.bottom + pTop + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
      if (doScroll != null && !phantom) {
        var hidden = display.cursor.style.display == "none";
        if (hidden) {
          display.cursor.style.display = "";
          display.cursor.style.left = coords.left + "px";
          display.cursor.style.top = (coords.top - display.viewOffset) + "px";
        }
        display.cursor.scrollIntoView(doScroll);
        if (hidden) display.cursor.style.display = "none";
      }
    }
docs: SCROLLING