selectallcommand.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/selectallcommand
  7. */
  8. import Command from '@ckeditor/ckeditor5-core/src/command';
  9. /**
  10. * The select all command.
  11. *
  12. * It is used by the {@link module:select-all/selectallediting~SelectAllEditing select all editing feature} to handle
  13. * the <kbd>Ctrl/⌘</kbd>+<kbd>A</kbd> keystroke.
  14. *
  15. * Executing this command changes the {@glink framework/guides/architecture/editing-engine#model model}
  16. * selection so it contains the entire content of the editable root of the editor the selection is
  17. * {@link module:engine/model/selection~Selection#anchor anchored} in.
  18. *
  19. * If the selection was anchored in a {@glink framework/guides/tutorials/implementing-a-block-widget nested editable}
  20. * (e.g. a caption of an image), the new selection will contain its entire content.
  21. *
  22. * @extends module:core/command~Command
  23. */
  24. export default class SelectAllCommand extends Command {
  25. /**
  26. * @inheritDoc
  27. */
  28. execute() {
  29. const model = this.editor.model;
  30. const limitElement = model.schema.getLimitElement( model.document.selection );
  31. model.change( writer => {
  32. writer.setSelection( limitElement, 'in' );
  33. } );
  34. }
  35. }