From 98e84ed5dacedcbc6bbb983390b051c29e9c2b36 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Fri, 9 Mar 2018 16:17:56 +0100 Subject: [PATCH 1/6] Added possibility to call CKEDITOR.editor.addCommand with command instance as param, added unit test --- core/editor.js | 6 ++++-- tests/core/command/command.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/editor.js b/core/editor.js index 568dc313678..ed10ad2b98f 100644 --- a/core/editor.js +++ b/core/editor.js @@ -740,12 +740,14 @@ * } * } ); * + * Since 4.10.0 this method 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 diff --git a/tests/core/command/command.js b/tests/core/command/command.js index c2fb0c7b8aa..9e395a07c7c 100644 --- a/tests/core/command/command.js +++ b/tests/core/command/command.js @@ -302,5 +302,30 @@ bender.test( { editor._.elementsPath.onClick( 0 ); wait(); + }, + + '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 ), + cmd1 = new CKEDITOR.command( editor, commandDefinition ); + + // Register command from command instance. + editor.addCommand( 'cmd1', cmd1 ); + + // 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' ), cmd1 ); + + // Registered command should't be same to another command with same definition. + assert.areNotSame( editor.getCommand( 'cmd2' ), cmd1 ); } } ); From 3827eeca1abc3b198d838ae567e351bf33107ab8 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Fri, 16 Mar 2018 15:10:36 +0100 Subject: [PATCH 2/6] Chaged docs entry --- core/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/editor.js b/core/editor.js index ed10ad2b98f..c7d2686720c 100644 --- a/core/editor.js +++ b/core/editor.js @@ -740,7 +740,7 @@ * } * } ); * - * Since 4.10.0 this method accepts `CKEDITOR.command` instance as param. + * 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/CKEDITOR.command} commandDefinition The command definition or the command instance. From 698142e5c50f6f4956944fe3d4baf1840933b5af Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Fri, 16 Mar 2018 15:10:45 +0100 Subject: [PATCH 3/6] Added test case for adding command from command subclass --- tests/core/command/command.js | 41 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/core/command/command.js b/tests/core/command/command.js index 9e395a07c7c..8756a802272 100644 --- a/tests/core/command/command.js +++ b/tests/core/command/command.js @@ -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( { @@ -314,18 +328,25 @@ bender.test( { }, style = new CKEDITOR.style( styleDefinition ), commandDefinition = new CKEDITOR.styleCommand( style ), - cmd1 = new CKEDITOR.command( editor, commandDefinition ); + cmd = new CKEDITOR.command( editor, commandDefinition ); - // Register command from command instance. - editor.addCommand( 'cmd1', cmd1 ); - - // Register command from command definition. - editor.addCommand( 'cmd2', commandDefinition ); + assertCommand( editor, cmd, commandDefinition ); + }, - // Registered command should be same as the command that was passed as definition. - assert.areSame( editor.getCommand( 'cmd1' ), cmd1 ); + '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 ); - // Registered command should't be same to another command with same definition. - assert.areNotSame( editor.getCommand( 'cmd2' ), cmd1 ); + assertCommand( editor, cmd, commandDefinition ); } + } ); From 8d4b75ea6157099a163ec71792d4f24bfbd28d5c Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Fri, 16 Mar 2018 15:13:50 +0100 Subject: [PATCH 4/6] Added changelog entry --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4a449b86576..7f508f0b8c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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: From bc8c44db43385c0f6ff25bfc7d8c80f6acc33ce1 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Fri, 16 Mar 2018 15:15:42 +0100 Subject: [PATCH 5/6] Removed unnecessary change --- tests/core/command/command.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/core/command/command.js b/tests/core/command/command.js index 8756a802272..074081c2456 100644 --- a/tests/core/command/command.js +++ b/tests/core/command/command.js @@ -348,5 +348,4 @@ bender.test( { assertCommand( editor, cmd, commandDefinition ); } - } ); From eeb62b29d42daa5b6c86e5d491e1cd60aef26c76 Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Fri, 23 Mar 2018 12:23:19 +0100 Subject: [PATCH 6/6] Add issue references. --- tests/core/command/command.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/core/command/command.js b/tests/core/command/command.js index 074081c2456..ed3bfbf0cde 100644 --- a/tests/core/command/command.js +++ b/tests/core/command/command.js @@ -318,6 +318,7 @@ bender.test( { wait(); }, + // (#1582) 'test addCommand from command instance': function() { var editor = this.editor, styleDefinition = { @@ -333,6 +334,7 @@ bender.test( { assertCommand( editor, cmd, commandDefinition ); }, + // (#1582) 'test addCommand from command subclass': function() { var editor = this.editor, styleDefinition = {