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

36 строки
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 { DOMDerivedSelection } from "./DOMDerivedSelection";
  13. import type EditorState from "./EditorState";
  14. const getDraftEditorSelectionWithNodes = require("./getDraftEditorSelectionWithNodes");
  15. /**
  16. * Convert the current selection range to an anchor/focus pair of offset keys
  17. * and values that can be interpreted by components.
  18. */
  19. function getDraftEditorSelection(editorState: EditorState, root: HTMLElement): DOMDerivedSelection {
  20. const selection = root.ownerDocument.defaultView.getSelection(); // No active selection.
  21. if (selection.rangeCount === 0) {
  22. return {
  23. selectionState: editorState.getSelection().set('hasFocus', false),
  24. needsRecovery: false
  25. };
  26. }
  27. return getDraftEditorSelectionWithNodes(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  28. }
  29. module.exports = getDraftEditorSelection;