Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. *
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. function isSelectionAtLeafStart(editorState) {
  13. var selection = editorState.getSelection();
  14. var anchorKey = selection.getAnchorKey();
  15. var blockTree = editorState.getBlockTree(anchorKey);
  16. var offset = selection.getStartOffset();
  17. var isAtStart = false;
  18. blockTree.some(function (leafSet) {
  19. if (offset === leafSet.get('start')) {
  20. isAtStart = true;
  21. return true;
  22. }
  23. if (offset < leafSet.get('end')) {
  24. return leafSet.get('leaves').some(function (leaf) {
  25. var leafStart = leaf.get('start');
  26. if (offset === leafStart) {
  27. isAtStart = true;
  28. return true;
  29. }
  30. return false;
  31. });
  32. }
  33. return false;
  34. });
  35. return isAtStart;
  36. }
  37. module.exports = isSelectionAtLeafStart;