enter.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module enter/enter
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import EnterCommand from './entercommand';
  10. import EnterObserver from './enterobserver';
  11. /**
  12. * The Enter feature. Handles the <kbd>Enter</kbd> and <kbd>Shift + Enter</kbd> keys in the editor.
  13. *
  14. * @extends module:core/plugin~Plugin
  15. */
  16. export default class Enter extends Plugin {
  17. /**
  18. * @inheritDoc
  19. */
  20. static get pluginName() {
  21. return 'Enter';
  22. }
  23. init() {
  24. const editor = this.editor;
  25. const view = editor.editing.view;
  26. const viewDocument = view.document;
  27. view.addObserver( EnterObserver );
  28. editor.commands.add( 'enter', new EnterCommand( editor ) );
  29. // TODO We may use the keystroke handler for that.
  30. this.listenTo( viewDocument, 'enter', ( evt, data ) => {
  31. editor.execute( 'enter' );
  32. data.preventDefault();
  33. view.scrollToTheSelection();
  34. }, { priority: 'low' } );
  35. }
  36. }