Skip to content

Commit

Permalink
Merge pull request #1423 from ckeditor/t/1419
Browse files Browse the repository at this point in the history
Fixed `alt + a` key combination for editor content selection on Windows
  • Loading branch information
mlewand authored Jan 16, 2018
2 parents bc9b698 + 500ac4f commit 4a8c9de
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ New Features:

Fixed Issues:

* [#1419](https://github.com/ckeditor/ckeditor-dev/issues/1419): Fixed: [Widged Selection](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widgetselection) selects editor content with `alt + a` key combination on Windows.
* [#1274](https://github.com/ckeditor/ckeditor-dev/issues/1274): Fixed: [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) does not match a single selected image using [`contextDefinition.cssSelector`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.balloontoolbar.contextDefinition-property-cssSelector) matcher.
* [#1232](https://github.com/ckeditor/ckeditor-dev/issues/1232): Fixed: [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) buttons should be registered as focusable elements.
* [#1342](https://github.com/ckeditor/ckeditor-dev/issues/1342): Fixed: [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) should be re-positioned after a [change](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.editor-event-change) event.
Expand Down
6 changes: 1 addition & 5 deletions plugins/widgetselection/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
editable = editor.editable();

editable.attachListener( doc, 'keydown', function( evt ) {
var data = evt.data.$;

// Ctrl/Cmd + A
if ( evt.data.getKey() == 65 && ( CKEDITOR.env.mac && data.metaKey || !CKEDITOR.env.mac && data.ctrlKey ) ) {

if ( evt.data.getKeystroke() == CKEDITOR.CTRL + 65 ) {
// Defer the call so the selection is already changed by the pressed keys.
CKEDITOR.tools.setTimeout( function() {

// Manage filler elements on keydown. If there is no need
// to add fillers, we need to check and clean previously used once.
if ( !widgetselection.addFillers( editable ) ) {
Expand Down
41 changes: 41 additions & 0 deletions tests/plugins/widgetselection/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* bender-tags: editor */
/* bender-ckeditor-plugins: widgetselection */

( function() {
'use strict';

bender.editor = true;

function testKeyCombination( editor, eventData, callCount ) {
var addFillersStub = sinon.stub( CKEDITOR.plugins.widgetselection, 'addFillers' );

editor.document.fire( 'keydown', new CKEDITOR.dom.event( eventData ) );

// Test has to be async because widgetSelection.addFillers is called inside setTimeout.
setTimeout( function() {
resume( function() {
addFillersStub.restore();
assert.areSame( callCount, addFillersStub.callCount, 'addFillers call count' );
} );
}, 50 );

wait();
}

bender.test( {
'test `ctrl + a` key combination': function() {
var editor = this.editor;
this.editorBot.setHtmlWithSelection( '<p contenteditable="false">Non-editable</p><p>This ^is text</p>' );

testKeyCombination( editor, { keyCode: 65, ctrlKey: true }, 1 );
},

'test ctrl + alt + a key combination': function() {
var editor = this.editor;
this.editorBot.setHtmlWithSelection( '<p contenteditable="false">Non-editable</p><p>This ^is text</p>' );

testKeyCombination( editor, { keyCode: 65, ctrlKey: true, altKey: true }, 0 );
}
} );

} )();
11 changes: 11 additions & 0 deletions tests/plugins/widgetselection/manual/specialcharacters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="editor1">
<p contenteditable="false">NonEditable</p>
<h1>Hello world!</h1>
<p>I&#39;m an instance of <a href="http://ckeditor.com">CKEditor</a>.</p>
</div>

<script>
CKEDITOR.replace( 'editor1', {
extraAllowedContent: 'p[contenteditable]'
} );
</script>
15 changes: 15 additions & 0 deletions tests/plugins/widgetselection/manual/specialcharacters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@bender-tags: 4.8.1, bug, 1419, widgetselection
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea,toolbar,link,format,sourcearea,widgetselection,elementspath

----

1. Set system settings to use Polish keyboard layout.
2. Focus editor instance.
3. Press `AltGr (right alt) + a` (or `option + a` on Mac) to insert `ą` letter.

## Expected
`ą` letter has been inserted at the caret position. Editor content has not been selected.

## Unexpected
`ą` letter has not been inserted and/or editor content has been selected.

0 comments on commit 4a8c9de

Please sign in to comment.