Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to call CKEDITOR.editor.addCommand with CKEDITOR.command instance as parameter #1786

Merged
merged 6 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Fixed Issues:
* [#1776](https://github.com/ckeditor/ckeditor-dev/issues/1776): [Image Base](https://ckeditor.com/cke4/addon/imagebase) empty caption placeholder is not hidden when blurred.
* [#1592](https://github.com/ckeditor/ckeditor-dev/issues/1592): [Image Base](https://ckeditor.com/cke4/addon/imagebase) caption is not visible after paste.

API Changes:

* [#1582](https://github.com/ckeditor/ckeditor-dev/issues/1582): The [`CKEDITOR.editor.addCommand`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#method-addCommand) can accept [`CKEDITOR.command`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_command.html) instance as parameter.

## CKEditor 4.9

New Features:
Expand Down
6 changes: 4 additions & 2 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,14 @@
* }
* } );
*
* Since 4.10.0 this method also accepts `CKEDITOR.command` instance as param.
*
* @param {String} commandName The indentifier name of the command.
* @param {CKEDITOR.commandDefinition} commandDefinition The command definition.
* @param {CKEDITOR.commandDefinition/CKEDITOR.command} commandDefinition The command definition or the command instance.
*/
addCommand: function( commandName, commandDefinition ) {
commandDefinition.name = commandName.toLowerCase();
var cmd = new CKEDITOR.command( this, commandDefinition );
var cmd = commandDefinition instanceof CKEDITOR.command ? commandDefinition : new CKEDITOR.command( this, commandDefinition );

// Update command when mode is set.
// This guarantees that commands added before first editor#mode
Expand Down
47 changes: 47 additions & 0 deletions tests/core/command/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ var READ_ONLY_CMDS = [
'preview', 'print', 'showblocks', 'showborders', 'source', 'toolbarCollapse', 'toolbarFocus', 'selectAll'
];

function assertCommand( editor, cmd, commandDefinition ) {
// Register command from command instance.
editor.addCommand( 'cmd1', cmd );

// Register command from command definition.
editor.addCommand( 'cmd2', commandDefinition );

// Registered command should be same as the command that was passed as definition.
assert.areSame( editor.getCommand( 'cmd1' ), cmd );

// Registered command should't be same to another command with same definition.
assert.areNotSame( editor.getCommand( 'cmd2' ), cmd );
}

bender.editor = true;

bender.test( {
Expand Down Expand Up @@ -302,5 +316,38 @@ bender.test( {
editor._.elementsPath.onClick( 0 );

wait();
},

// (#1582)
'test addCommand from command instance': function() {
var editor = this.editor,
styleDefinition = {
element: 'span',
attributes: {
bar: 'foo'
}
},
style = new CKEDITOR.style( styleDefinition ),
commandDefinition = new CKEDITOR.styleCommand( style ),
cmd = new CKEDITOR.command( editor, commandDefinition );

assertCommand( editor, cmd, commandDefinition );
},

// (#1582)
'test addCommand from command subclass': function() {
var editor = this.editor,
styleDefinition = {
element: 'span',
attributes: {
bar: 'foo'
}
},
subCommand = CKEDITOR.tools.createClass( { base: CKEDITOR.command } ),
style = new CKEDITOR.style( styleDefinition ),
commandDefinition = new CKEDITOR.styleCommand( style ),
cmd = new subCommand( editor, commandDefinition );

assertCommand( editor, cmd, commandDefinition );
}
} );