From 498dc1108492cafd5d622752c95e24b081e3a091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Thu, 30 Mar 2017 12:30:59 +0200 Subject: [PATCH 1/5] The getCommandKeystroke method accepts command name. --- core/editor.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/core/editor.js b/core/editor.js index 8dfce7fed15..d39dc2451c4 100644 --- a/core/editor.js +++ b/core/editor.js @@ -1326,27 +1326,31 @@ /** * Returns the keystroke that is assigned to a specified {@link CKEDITOR.command}. If no keystroke is assigned, * it returns null. + * Since version 4.7.0 this function also accepts a command name instead of a command instance. * * @since 4.6.0 - * @param {CKEDITOR.command} command + * @param {CKEDITOR.command|String} command The {@link CKEDITOR.command} instance or a string with command name. * @returns {Number} The keystroke assigned to the provided command or null if there is no keystroke. */ getCommandKeystroke: function( command ) { - var commandName = command.name, - keystrokes = this.keystrokeHandler.keystrokes, - key; + var commandInstance = ( typeof command === 'string' ? this.getCommand( command ) : command ); - // Some commands have a fake keystroke - for example CUT/COPY/PASTE commands are handled natively. - if ( command.fakeKeystroke ) { - return command.fakeKeystroke; - } + if ( commandInstance ) { + var commandName = commandInstance && commandInstance.name, + keystrokes = this.keystrokeHandler.keystrokes, + key; - for ( key in keystrokes ) { - if ( keystrokes.hasOwnProperty( key ) && keystrokes[ key ] == commandName ) { - return key; + // Some commands have a fake keystroke - for example CUT/COPY/PASTE commands are handled natively. + if ( commandInstance.fakeKeystroke ) { + return commandInstance.fakeKeystroke; } - } + for ( key in keystrokes ) { + if ( keystrokes.hasOwnProperty( key ) && keystrokes[ key ] == commandName ) { + return key; + } + } + } return null; }, From 09e3e020d8bc9211979d10048d4ed9a1b30e8693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Thu, 30 Mar 2017 12:33:30 +0200 Subject: [PATCH 2/5] Tests: getCommandKeystroke test adjustments. --- tests/core/editor/keystrokehandler.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/core/editor/keystrokehandler.js b/tests/core/editor/keystrokehandler.js index 4658cfc0648..24835ede900 100644 --- a/tests/core/editor/keystrokehandler.js +++ b/tests/core/editor/keystrokehandler.js @@ -29,8 +29,14 @@ bender.test( editor.setKeystroke( keyCombo1, command1 ); assert.areEqual( command1, keystrokes[ keyCombo1 ] ); + + // Get by command instance. keystroke = editor.getCommandKeystroke( editor.getCommand( command1 ) ); - assert.areEqual( keyCombo1, keystroke, 'Keystrokes should be equal.' ); + assert.areEqual( keyCombo1, keystroke, 'Keystrokes should be equal (command).' ); + + // Get by command name. + keystroke = editor.getCommandKeystroke( command1 ); + assert.areEqual( keyCombo1, keystroke, 'Keystrokes should be equal (command name).' ); }, 'test keystroke array assignment': function() { @@ -51,10 +57,17 @@ bender.test( assert.areEqual( command1, keystrokes[ keyCombo1 ] ); assert.areEqual( command2, keystrokes[ keyCombo2 ] ); + // Get by command instance. keystroke1 = editor.getCommandKeystroke( editor.getCommand( command1 ) ); keystroke2 = editor.getCommandKeystroke( editor.getCommand( command2 ) ); - assert.areEqual( keyCombo1, keystroke1, 'Keystrokes should be equal.' ); - assert.areEqual( keyCombo2, keystroke2, 'Keystrokes should be equal.' ); + assert.areEqual( keyCombo1, keystroke1, 'Keystrokes should be equal (command).' ); + assert.areEqual( keyCombo2, keystroke2, 'Keystrokes should be equal (command).' ); + + // Get by command name. + keystroke1 = editor.getCommandKeystroke( command1 ); + keystroke2 = editor.getCommandKeystroke( command2 ); + assert.areEqual( keyCombo1, keystroke1, 'Keystrokes should be equal (command name).' ); + assert.areEqual( keyCombo2, keystroke2, 'Keystrokes should be equal (command name).' ); }, 'test editor#key event': function() { @@ -76,5 +89,10 @@ bender.test( assert.areSame( CKEDITOR.CTRL + CKEDITOR.SHIFT + 66, evtData.keyCode, 'keyCode' ); assert.isInstanceOf( CKEDITOR.dom.event, evtData.domEvent, 'domEvent' ); assert.areSame( 66, evtData.domEvent.getKey(), 'domEvent.getKey()' ); + }, + + 'test editor#getCommandKeystroke with empty name': function() { + var editor = this.editor; + assert.isNull( editor.getCommandKeystroke( '' ), 'Keystrokes should be null.' ); } } ); From f12ad09119fd4c88888ffaa660610de2c6e5ee99 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Fri, 31 Mar 2017 11:30:40 +0200 Subject: [PATCH 3/5] Corrected assertion message, added API docs returned type. --- core/editor.js | 2 +- tests/core/editor/keystrokehandler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/editor.js b/core/editor.js index d39dc2451c4..a01f8a443c6 100644 --- a/core/editor.js +++ b/core/editor.js @@ -1330,7 +1330,7 @@ * * @since 4.6.0 * @param {CKEDITOR.command|String} command The {@link CKEDITOR.command} instance or a string with command name. - * @returns {Number} The keystroke assigned to the provided command or null if there is no keystroke. + * @returns {Number/null} The keystroke assigned to the provided command or `null` if there is no keystroke. */ getCommandKeystroke: function( command ) { var commandInstance = ( typeof command === 'string' ? this.getCommand( command ) : command ); diff --git a/tests/core/editor/keystrokehandler.js b/tests/core/editor/keystrokehandler.js index 24835ede900..14b6505cf9f 100644 --- a/tests/core/editor/keystrokehandler.js +++ b/tests/core/editor/keystrokehandler.js @@ -93,6 +93,6 @@ bender.test( 'test editor#getCommandKeystroke with empty name': function() { var editor = this.editor; - assert.isNull( editor.getCommandKeystroke( '' ), 'Keystrokes should be null.' ); + assert.isNull( editor.getCommandKeystroke( '' ), 'Returned keystroke.' ); } } ); From c8d5e713977aecc9ba67eb7dad9a8c4b69c6a479 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Fri, 31 Mar 2017 11:37:14 +0200 Subject: [PATCH 4/5] Docs: more docs corrections separator. [skip ci] --- core/editor.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/editor.js b/core/editor.js index a01f8a443c6..4e31a286e8e 100644 --- a/core/editor.js +++ b/core/editor.js @@ -1325,11 +1325,12 @@ /** * Returns the keystroke that is assigned to a specified {@link CKEDITOR.command}. If no keystroke is assigned, - * it returns null. - * Since version 4.7.0 this function also accepts a command name instead of a command instance. + * it returns `null`. + * + * Since version 4.7.0 this function also accepts `command` parameter as a string. * * @since 4.6.0 - * @param {CKEDITOR.command|String} command The {@link CKEDITOR.command} instance or a string with command name. + * @param {CKEDITOR.command/String} command The {@link CKEDITOR.command} instance or a string with command name. * @returns {Number/null} The keystroke assigned to the provided command or `null` if there is no keystroke. */ getCommandKeystroke: function( command ) { From 87e4934c894f88e6fa77196b4bb4e8f184de0fd5 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Fri, 31 Mar 2017 11:47:45 +0200 Subject: [PATCH 5/5] Changelog entry. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 24609e09658..25945112231 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ New Features: * [#16847](http://dev.ckeditor.com/ticket/16847): Added a support for parsing and inlining any formatting created using Microsoft Word's style system to the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin. * [#16818](http://dev.ckeditor.com/ticket/16818): Added table cell height parsing in the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin. * [#16850](http://dev.ckeditor.com/ticket/16850): Added new `config.enableContextMenu` configuration option for enabling and disabling [Context Menu](http://ckeditor.com/addon/contextmenu). +* [#16937](http://dev.ckeditor.com/ticket/16937): The `command` parameter in the [CKEDITOR.editor.getCommandKeystroke](http://docs.ckeditor.dev/#!/api/CKEDITOR.editor-method-getCommandKeystroke) accepts also command name as an argument. Fixed Issues: