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

45 строки
1.1 KiB

  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. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type EditorState from "./EditorState";
  13. function isSelectionAtLeafStart(editorState: EditorState): boolean {
  14. const selection = editorState.getSelection();
  15. const anchorKey = selection.getAnchorKey();
  16. const blockTree = editorState.getBlockTree(anchorKey);
  17. const offset = selection.getStartOffset();
  18. let isAtStart = false;
  19. blockTree.some(leafSet => {
  20. if (offset === leafSet.get('start')) {
  21. isAtStart = true;
  22. return true;
  23. }
  24. if (offset < leafSet.get('end')) {
  25. return leafSet.get('leaves').some(leaf => {
  26. const leafStart = leaf.get('start');
  27. if (offset === leafStart) {
  28. isAtStart = true;
  29. return true;
  30. }
  31. return false;
  32. });
  33. }
  34. return false;
  35. });
  36. return isAtStart;
  37. }
  38. module.exports = isSelectionAtLeafStart;