insertspecialcharactercommand.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module special-characters/insertspecialcharactercommand
  7. */
  8. import Command from '@ckeditor/ckeditor5-core/src/command';
  9. /**
  10. * @extends module:core/command~Command
  11. */
  12. export default class InsertSpecialCharacterCommand extends Command {
  13. /**
  14. * Creates an instance of the command.
  15. *
  16. * @param {module:core/editor/editor~Editor} editor
  17. */
  18. constructor( editor ) {
  19. super( editor );
  20. /**
  21. * @readonly
  22. * @private
  23. * @member {module:typing/inputcommand~InputCommand} #_inputCommand
  24. */
  25. this._inputCommand = editor.commands.get( 'input' );
  26. // Use the state of `Input` command to determine whether the special characters could be inserted.
  27. this.bind( 'isEnabled' ).to( this._inputCommand, 'isEnabled' );
  28. }
  29. /**
  30. * @param {Object} options
  31. * @param {String} options.item An id of the special character that should be added to the editor.
  32. */
  33. execute( options ) {
  34. const editor = this.editor;
  35. const character = editor.plugins.get( 'SpecialCharacters' ).getCharacter( options.item );
  36. this._inputCommand.execute( { text: character } );
  37. }
  38. }