pasteplaintext.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module clipboard/clipboard
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ClipboardObserver from './clipboardobserver';
  10. /**
  11. * The plugin detects user intentions for pasting plain text.
  12. *
  13. * For example, it detects <kbd>ctrl/cmd</kbd> + <kbd>shift</kbd> + <kbd>ctrl/v</kbd> keystroke.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class PastePlainText extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. static get pluginName() {
  22. return 'PastePlainText';
  23. }
  24. /**
  25. * @inheritDoc
  26. */
  27. init() {
  28. const view = this.editor.editing.view;
  29. const viewDocument = view.document;
  30. let shiftPressed = false;
  31. view.addObserver( ClipboardObserver );
  32. this.listenTo( viewDocument, 'keydown', ( evt, data ) => {
  33. shiftPressed = data.shiftKey;
  34. } );
  35. this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
  36. if ( shiftPressed ) {
  37. data.asPlainText = true;
  38. }
  39. }, { priority: 'high' } );
  40. }
  41. }