You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

editOnCopy.js 876 B

3 years ago
123456789101112131415161718192021222324252627282930313233
  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. var getFragmentFromSelection = require("./getFragmentFromSelection");
  13. /**
  14. * If we have a selection, create a ContentState fragment and store
  15. * it in our internal clipboard. Subsequent paste events will use this
  16. * fragment if no external clipboard data is supplied.
  17. */
  18. function editOnCopy(editor, e) {
  19. var editorState = editor._latestEditorState;
  20. var selection = editorState.getSelection(); // No selection, so there's nothing to copy.
  21. if (selection.isCollapsed()) {
  22. e.preventDefault();
  23. return;
  24. }
  25. editor.setClipboard(getFragmentFromSelection(editor._latestEditorState));
  26. }
  27. module.exports = editOnCopy;