formatcommand.js 701 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Command from '../command.js';
  7. export default class FormatCommand extends Command {
  8. constructor( editor ) {
  9. super( editor );
  10. this.set( 'value', 'paragraph' );
  11. this.listenTo( editor.document.selection, 'change', () => {
  12. const position = editor.document.selection.getFirstPosition();
  13. const parent = position.parent;
  14. switch ( parent.name ) {
  15. case 'h2':
  16. this.value = 'heading1';
  17. break;
  18. case 'h3':
  19. this.value = 'heading2';
  20. break;
  21. case 'h4':
  22. this.value = 'heading3';
  23. break;
  24. }
  25. } );
  26. }
  27. }