selectAll.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var UI = require('../../document/UI.js');
  3. require('../../utils/dataTransfer/Clipboard.js');
  4. var isContentEditable = require('../../utils/edit/isContentEditable.js');
  5. var selection = require('../../utils/focus/selection.js');
  6. var setSelection = require('./setSelection.js');
  7. /**
  8. * Expand a selection like the browser does when pressing Ctrl+A.
  9. */ function selectAll(target) {
  10. if (selection.hasOwnSelection(target)) {
  11. return setSelection.setSelection({
  12. focusNode: target,
  13. anchorOffset: 0,
  14. focusOffset: UI.getUIValue(target).length
  15. });
  16. }
  17. var _getContentEditable;
  18. const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
  19. setSelection.setSelection({
  20. focusNode,
  21. anchorOffset: 0,
  22. focusOffset: focusNode.childNodes.length
  23. });
  24. }
  25. function isAllSelected(target) {
  26. if (selection.hasOwnSelection(target)) {
  27. return UI.getUISelection(target).startOffset === 0 && UI.getUISelection(target).endOffset === UI.getUIValue(target).length;
  28. }
  29. var _getContentEditable;
  30. const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
  31. const selection$1 = target.ownerDocument.getSelection();
  32. return (selection$1 === null || selection$1 === undefined ? undefined : selection$1.anchorNode) === focusNode && selection$1.focusNode === focusNode && selection$1.anchorOffset === 0 && selection$1.focusOffset === focusNode.childNodes.length;
  33. }
  34. exports.isAllSelected = isAllSelected;
  35. exports.selectAll = selectAll;