Skip to content

Commit

Permalink
Merge branch 't/13446'
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Jan 5, 2017
2 parents eab8e4b + ec6fc2b commit 8437204
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 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:

* [#13446](http://dev.ckeditor.com/ticket/13446): [Chrome] Fixed: It is possible to type in an unfocused inline editor.
* [#14856](http://dev.ckeditor.com/ticket/14856): Fixed: Font size and font family reset each other when modified at certain positions.
* [#13818](http://dev.ckeditor.com/ticket/13818): Fixed: Allow to group [Widget](http://ckeditor.com/addon/widget) [style definitions](http://docs.ckeditor.com/#!/guide/dev_styles-section-widget-styles), so applying one style disables the other.
* [#16745](http://dev.ckeditor.com/ticket/16745): [Edge] Fixed: List items are lost when pasted from word.
Expand Down
8 changes: 8 additions & 0 deletions core/focusmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,17 @@
return;

function doBlur() {
var editor = this._.editor;

if ( this.hasFocus ) {
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() ) {
editor.window.$.getSelection().removeAllRanges();
}

var ct = this._.editor.container;
ct && ct.removeClass( 'cke_focus' );
this._.editor.fire( 'blur' );
Expand Down
12 changes: 11 additions & 1 deletion tests/core/editor/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,19 @@

bender.test( {
'init': function() {
var initialDelay = CKEDITOR.focusManager._.blurDelay;

// Due to asynchronous nature of editor's blurring,
// blur handler is called after switching focus to the next editor.
// In case of inline editors in Chrome it causes to clear the selection
// and breaks the editor.
CKEDITOR.focusManager._.blurDelay = 0;

for ( var name in bender.editors ) {
bender.editors[ name ].insertText( name );
}

CKEDITOR.focusManager._.blurDelay = initialDelay;
},

'test config.title implies editor.title': function() {
Expand Down Expand Up @@ -243,4 +253,4 @@
wait();
}
} );
} )();
} )();
49 changes: 48 additions & 1 deletion tests/core/focusmanager/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,53 @@ bender.test( {
} );

wait();
},

// #13446
'test cleaning up selection on blur (inline editor)': function() {
if ( !CKEDITOR.env.chrome ) {
assert.ignore();
}

var el = CKEDITOR.document.createElement( 'div' );
CKEDITOR.document.getBody().append( el );
el.setAttribute( 'contenteditable', true );

var editor = CKEDITOR.inline( el );

editor.on( 'instanceReady', function() {
resume( function() {
editor.on( 'blur', function() {
resume( function() {
assert.areSame( 'None', editor.getSelection().getNative().type );
} );
} );

CKEDITOR.document.getById( 'focusable' ).focus();
wait();
} );
} );

el.focus();
wait();
},

// #13446
'test preserving selection on blur (classic editor)': function() {
if ( !CKEDITOR.env.chrome ) {
assert.ignore();
}

var editor = this.editor;

editor.focus();

bender.tools.focus( CKEDITOR.document.getById( 'focusable' ), function() {
// Chrome doesn't reset selection after blurring [contenteditable=true],
// however is not troublesome for classic editor (because the focus is moved
// outside the whole editor's window), so it should be left untouched there.
assert.areSame( 'Caret', editor.getSelection().getNative().type );
} );
}

} );
} );
14 changes: 14 additions & 0 deletions tests/core/focusmanager/manual/typinginunfocusedinlineeditor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<body>
<div id="editor" contenteditable="true">
<p>Example text</p>
</div>
<button>I'm a button!</button>

<script>
if ( !CKEDITOR.env.chrome ) {
bender.ignore();
}

CKEDITOR.inline( 'editor' );
</script>
</body>
14 changes: 14 additions & 0 deletions tests/core/focusmanager/manual/typinginunfocusedinlineeditor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-tags: tc, editor, focus, 13446, 4.6.2
@bender-ui: collapsed
@bender-ckeditor-plugins: toolbar, floatingspace, basicstyles

###ONLY IN CHROME###

----

1. Click the text. Inline editor should receive focus.
2. Press `Tab` to move focus to the button.
3. Type something.

**Expected:**
* Text is not inserted into the editor.

0 comments on commit 8437204

Please sign in to comment.