setSelection.js 1.1 KB

123456789101112131415161718192021
  1. 'use strict';
  2. var UI = require('../../document/UI.js');
  3. require('../../utils/dataTransfer/Clipboard.js');
  4. var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
  5. /**
  6. * Set the selection
  7. */ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
  8. var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
  9. const typeAndSelection = getTargetTypeAndSelection.getTargetTypeAndSelection(focusNode);
  10. if (typeAndSelection.type === 'input') {
  11. return UI.setUISelection(focusNode, {
  12. anchorOffset,
  13. focusOffset
  14. });
  15. }
  16. (_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === undefined ? undefined : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === undefined ? undefined : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
  17. }
  18. exports.setSelection = setSelection;