| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module mention/mentioncommand
- */
- import Command from '@ckeditor/ckeditor5-core/src/command';
- import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
- /**
- * The mention command.
- *
- * @extends module:core/command~Command
- */
- export default class MentionCommand extends Command {
- /**
- * @inheritDoc
- */
- refresh() {
- // @todo implement refresh
- this.isEnabled = true;
- }
- /**
- * Executes the command.
- *
- * @protected
- * @param {Object} [options] Options for the executed command.
- * @param {String} [options.marker='@'] The mention marker.
- * @param {String} options.mention.
- * @param {String} [options.range].
- * @fires execute
- */
- execute( options = {} ) {
- const model = this.editor.model;
- const document = model.document;
- const selection = document.selection;
- const marker = options.marker || '@';
- const mention = options.mention;
- const range = options.range || selection.getFirstRange();
- const name = mention.name || mention;
- model.change( writer => {
- writer.remove( range );
- const selectionAttributes = toMap( selection.getAttributes() );
- const attributes = new Map( selectionAttributes.entries() );
- attributes.set( 'mention', mention );
- writer.insertText( `${ marker }${ name }`, attributes, range.start );
- writer.insertText( ' ', selectionAttributes, model.document.selection.focus );
- } );
- }
- }
|