selectallediting.js 1.3 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 select-all/selectallediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import { getCode, parseKeystroke } from '@ckeditor/ckeditor5-utils/src/keyboard';
  10. import SelectAllCommand from './selectallcommand';
  11. const SELECT_ALL_KEYSTROKE = parseKeystroke( 'Ctrl+A' );
  12. /**
  13. * The select all editing feature.
  14. *
  15. * It registers the `'selectAll'` {@link module:select-all/selectallcommand~SelectAllCommand command}
  16. * and the <kbd>Ctrl/⌘</kbd>+<kbd>A</kbd> keystroke listener which executes it.
  17. *
  18. * @extends module:core/plugin~Plugin
  19. */
  20. export default class SelectAllEditing extends Plugin {
  21. /**
  22. * @inheritDoc
  23. */
  24. static get pluginName() {
  25. return 'SelectAllEditing';
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. init() {
  31. const editor = this.editor;
  32. const view = editor.editing.view;
  33. const viewDocument = view.document;
  34. editor.commands.add( 'selectAll', new SelectAllCommand( editor ) );
  35. this.listenTo( viewDocument, 'keydown', ( eventInfo, domEventData ) => {
  36. if ( getCode( domEventData ) === SELECT_ALL_KEYSTROKE ) {
  37. editor.execute( 'selectAll' );
  38. domEventData.preventDefault();
  39. }
  40. } );
  41. }
  42. }