Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 DraftEditor from "./DraftEditor.react";
  13. const DraftJsDebugLogging = require("./DraftJsDebugLogging");
  14. const EditorState = require("./EditorState");
  15. const getContentEditableContainer = require("./getContentEditableContainer");
  16. const getDraftEditorSelection = require("./getDraftEditorSelection");
  17. function editOnSelect(editor: DraftEditor): void {
  18. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  19. if (editor._blockSelectEvents) {
  20. const editorState = editor.props.editorState;
  21. const selectionState = editorState.getSelection();
  22. DraftJsDebugLogging.logBlockedSelectionEvent({
  23. // For now I don't think we need any other info
  24. anonymizedDom: 'N/A',
  25. extraParams: JSON.stringify({
  26. stacktrace: new Error().stack
  27. }),
  28. selectionState: JSON.stringify(selectionState.toJS())
  29. });
  30. }
  31. return;
  32. }
  33. let editorState = editor.props.editorState;
  34. const documentSelection = getDraftEditorSelection(editorState, getContentEditableContainer(editor));
  35. const updatedSelectionState = documentSelection.selectionState;
  36. if (updatedSelectionState !== editorState.getSelection()) {
  37. if (documentSelection.needsRecovery) {
  38. editorState = EditorState.forceSelection(editorState, updatedSelectionState);
  39. } else {
  40. editorState = EditorState.acceptSelection(editorState, updatedSelectionState);
  41. }
  42. editor.update(editorState);
  43. }
  44. }
  45. module.exports = editOnSelect;