setSelectionRange.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import '../../utils/dataTransfer/Clipboard.js';
  2. import { isContentEditable } from '../../utils/edit/isContentEditable.js';
  3. import { hasOwnSelection } from '../../utils/focus/selection.js';
  4. import { setSelection } from './setSelection.js';
  5. /**
  6. * Backward-compatible selection.
  7. *
  8. * Handles input elements and contenteditable if it only contains a single text node.
  9. */ function setSelectionRange(element, anchorOffset, focusOffset) {
  10. var _element_firstChild;
  11. if (hasOwnSelection(element)) {
  12. return setSelection({
  13. focusNode: element,
  14. anchorOffset,
  15. focusOffset
  16. });
  17. }
  18. /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === undefined ? undefined : _element_firstChild.nodeType) === 3) {
  19. return setSelection({
  20. focusNode: element.firstChild,
  21. anchorOffset,
  22. focusOffset
  23. });
  24. }
  25. /* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
  26. }
  27. export { setSelectionRange };