8
0

enter.js 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 editingView = editor.editing.view;
  26. editingView.addObserver( EnterObserver );
  27. editor.commands.add( 'enter', new EnterCommand( editor ) );
  28. // TODO We may use the keystroke handler for that.
  29. this.listenTo( editingView, 'enter', ( evt, data ) => {
  30. editor.execute( 'enter' );
  31. data.preventDefault();
  32. editingView.scrollToTheSelection();
  33. }, { priority: 'low' } );
  34. }
  35. }