Skip to content

Commit

Permalink
Merge branch 't/16937' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Mar 31, 2017
2 parents e1bf2df + 87e4934 commit da7d4f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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:

Expand Down
33 changes: 19 additions & 14 deletions core/editor.js
Expand Up @@ -1325,28 +1325,33 @@

/**
* Returns the keystroke that is assigned to a specified {@link CKEDITOR.command}. If no keystroke is assigned,
* it returns null.
* it returns `null`.
*
* Since version 4.7.0 this function also accepts `command` parameter as a string.
*
* @since 4.6.0
* @param {CKEDITOR.command} command
* @returns {Number} The keystroke assigned to the provided command or null if there is no keystroke.
* @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 ) {
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;
},

Expand Down
24 changes: 21 additions & 3 deletions tests/core/editor/keystrokehandler.js
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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( '' ), 'Returned keystroke.' );
}
} );

0 comments on commit da7d4f1

Please sign in to comment.