code: function updateSelection(cm) {
      var display = cm.display;
      var collapsed = posEq(cm.doc.sel.from, cm.doc.sel.to);
      if (collapsed || cm.options.showCursorWhenSelecting)
        updateSelectionCursor(cm);
      else
        display.cursor.style.display = display.otherCursor.style.display = "none";
      if (!collapsed)
        updateSelectionRange(cm);
      else
        display.selectionDiv.style.display = "none";
  
      // Move the hidden textarea near the cursor to prevent scrolling artifacts
      if (cm.options.moveInputWithCursor) {
        var headPos = cursorCoords(cm, cm.doc.sel.head, "div");
        var wrapOff = getRect(display.wrapper), lineOff = getRect(display.lineDiv);
        display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
                                                          headPos.top + lineOff.top - wrapOff.top)) + "px";
        display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
                                                           headPos.left + lineOff.left - wrapOff.left)) + "px";
      }
    }
docs: SELECTION / CURSOR