| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module table/commands/splitcellcommand
- */
- import Command from '@ckeditor/ckeditor5-core/src/command';
- import TableUtils from '../tableutils';
- /**
- * The split cell command.
- *
- * The command is registered by {@link module:table/tableediting~TableEditing} as `'splitTableCellVertically'`
- * and `'splitTableCellHorizontally'` editor commands.
- *
- * You can split any cell vertically or horizontally by executing this command. For example, to split the selected table cell vertically:
- *
- * editor.execute( 'splitTableCellVertically' );
- *
- * @extends module:core/command~Command
- */
- export default class SplitCellCommand extends Command {
- /**
- * Creates a new `SplitCellCommand` instance.
- *
- * @param {module:core/editor/editor~Editor} editor The editor on which this command will be used.
- * @param {Object} options
- * @param {String} options.direction Indicates whether the command should split cells `'horizontally'` or `'vertically'`.
- */
- constructor( editor, options = {} ) {
- super( editor );
- /**
- * The direction that indicates which cell will be split.
- *
- * @readonly
- * @member {String} #direction
- */
- this.direction = options.direction || 'horizontally';
- }
- /**
- * @inheritDoc
- */
- refresh() {
- const model = this.editor.model;
- const doc = model.document;
- const element = doc.selection.getFirstPosition().parent;
- this.isEnabled = element.is( 'tableCell' );
- }
- /**
- * @inheritDoc
- */
- execute() {
- const model = this.editor.model;
- const document = model.document;
- const selection = document.selection;
- const firstPosition = selection.getFirstPosition();
- const tableCell = firstPosition.parent;
- const isHorizontally = this.direction === 'horizontally';
- const tableUtils = this.editor.plugins.get( TableUtils );
- if ( isHorizontally ) {
- tableUtils.splitCellHorizontally( tableCell, 2 );
- } else {
- tableUtils.splitCellVertically( tableCell, 2 );
- }
- }
- }
|