setSelection.js 1.0 KB

12345678910111213141516171819
  1. import { setUISelection } from '../../document/UI.js';
  2. import '../../utils/dataTransfer/Clipboard.js';
  3. import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
  4. /**
  5. * Set the selection
  6. */ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
  7. var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
  8. const typeAndSelection = getTargetTypeAndSelection(focusNode);
  9. if (typeAndSelection.type === 'input') {
  10. return setUISelection(focusNode, {
  11. anchorOffset,
  12. focusOffset
  13. });
  14. }
  15. (_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);
  16. }
  17. export { setSelection };