Skip to content

Commit

Permalink
Merge branch 't/16825' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Mar 16, 2017
2 parents 3eb1f7d + e977e2a commit 33bd628
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New Features:

Fixed Issues:

* [#16825](http://dev.ckeditor.com/ticket/16825): Fixed: [Chrome] Error thrown when destroying focused inline editor.
* [#16857](http://dev.ckeditor.com/ticket/16857): Fixed: Ctrl + Shift + V blocked by copy formatting.
* [#14714](http://dev.ckeditor.com/ticket/14714): [Webkit/Blink] Fixed: Exception thrown on refocusing a blurred inline editor.
* [#16821](http://dev.ckeditor.com/ticket/16821): Fixed: Extraneous `spans` with `height` style stacked when [pasting from Word](http://ckeditor.com/addon/pastefromword).
Expand Down
15 changes: 9 additions & 6 deletions core/focusmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@
* @member CKEDITOR.focusManager
*/
blur: function( noDelay ) {
if ( this._.locked )
if ( this._.locked ) {
return;
}

function doBlur() {
var editor = this._.editor;
Expand All @@ -157,8 +158,9 @@
this.hasFocus = false;

// Blink browsers leave selection in `[contenteditable=true]`
// when it's blurred and it's neccessary to remove it manually for inline editor. (#13446)
if ( CKEDITOR.env.chrome && editor.editable().isInline() ) {
// when it's blurred and it's necessary to remove it manually for inline editor. (#13446)
// It seems to be related to https://bugs.chromium.org/p/chromium/issues/detail?id=433303.
if ( CKEDITOR.env.chrome && editor.editable() && editor.editable().isInline() ) {
editor.window.$.getSelection().removeAllRanges();
}

Expand All @@ -168,13 +170,14 @@
}
}

if ( this._.timer )
if ( this._.timer ) {
clearTimeout( this._.timer );
}

var delay = CKEDITOR.focusManager._.blurDelay;
if ( noDelay || !delay )
if ( noDelay || !delay ) {
doBlur.call( this );
else {
} else {
this._.timer = CKEDITOR.tools.setTimeout( function() {
delete this._.timer;
doBlur.call( this );
Expand Down
1 change: 1 addition & 0 deletions tests/core/editor/destroy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="focused"></div>
30 changes: 26 additions & 4 deletions tests/core/editor/destroy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: toolbar,button,stylescombo */
/* bender-ckeditor-plugins: toolbar,button,stylescombo,wysiwygarea */

bender.editor = true;
bender.editor = {
config: {
startupFocus: true
}
};

bender.test(
{
bender.test( {
'test destroy editor with rich combo panel opened': function() {
var bot = this.editorBot, editor = this.editor;
bot.combo( 'Styles', function( combo ) {
Expand Down Expand Up @@ -58,5 +61,24 @@ bender.test(
'CKEDITOR.warn error code should be "editor-incorrect-destroy".' );
}, 0 );

},

'test check editable existence on blur': function() {
CKEDITOR.replace( 'focused', {
on: {
instanceReady: function( evt ) {
resume( function() {
var editor = evt.sender;
// Simulate the circumstances instead of creating them.
editor.focusManager.hasFocus = true;
sinon.stub( editor, 'editable' ).returns( null );
editor.focusManager.blur( 1 );
assert.pass();
} );
}
}
} );

wait();
}
} );
18 changes: 18 additions & 0 deletions tests/core/editor/manual/focusdestroy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<textarea name="editor1" id="editor1" cols="30" rows="10">
</textarea>
<script>
if ( !CKEDITOR.env.chrome ) {
bender.ignore();
}

var editor = CKEDITOR.replace( 'editor1', {
on: {
instanceReady: function() {
editor.editable().on( 'keydown', function() {
editor.focusManager.blur();
editor.destroy();
} );
}
}
} );
</script>
14 changes: 14 additions & 0 deletions tests/core/editor/manual/focusdestroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-tags: tc, 4.7.0, 16825,
@bender-ui: collapsed
@bender-ckeditor-plugins: toolbar, wysiwygarea, about, elementspath

1. Focus the editor.
1. Press any printable key.

## Expected

Editor gets blurred, destroyed and there are no errors in the console.

## Unexpected

There is a `Cannot read property 'isInline' of null` error in the console.

0 comments on commit 33bd628

Please sign in to comment.