Skip to content

Commit

Permalink
Merge branch 't/14825'
Browse files Browse the repository at this point in the history
  • Loading branch information
Comandeer committed Aug 26, 2016
2 parents 2da5841 + 3c63a36 commit 3f95046
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -14,6 +14,7 @@ Fixed Issues:
* [#13548](http://dev.ckeditor.com/ticket/13548): [IE] Fixed: Clicking the [elements path](http://ckeditor.com/addon/elementspath) disables Cut and Copy icons.
* [#13812](http://dev.ckeditor.com/ticket/13812): Fixed: When aborting file upload the placeholder for image is left.
* [#14659](http://dev.ckeditor.com/ticket/14659): [Blink] Fixed: Content scrolled to the top after closing the dialog in a [`<div>`-based editor](http://ckeditor.com/addon/divarea).
* [#14825](http://dev.ckeditor.com/ticket/14825): [Edge] Fixed: Focusing editor causes unwanted scrolling due to dropped support of `setActive` method.

## CKEditor 4.5.10

Expand Down
34 changes: 31 additions & 3 deletions core/editable.js
Expand Up @@ -74,10 +74,21 @@
}
}

// [IE] Use instead "setActive" method to focus the editable if it belongs to
// the host page document, to avoid bringing an unexpected scroll.
// [Edge] Starting from EdgeHTML 14.14393, it does not support `setActive`. We need to use focus which
// causes unexpected scroll. Store scrollTop value so it can be restored after focusing editor.
// Scroll only happens if the editor is focused for the first time. (#14825)
if ( CKEDITOR.env.edge && CKEDITOR.env.version > 14 && !this.hasFocus && this.getDocument().equals( CKEDITOR.document ) ) {
this.editor._.previousScrollTop = this.$.scrollTop;
}

// [IE] Use instead "setActive" method to focus the editable if it belongs to the host page document,
// to avoid bringing an unexpected scroll.
try {
this.$[ CKEDITOR.env.ie && this.getDocument().equals( CKEDITOR.document ) ? 'setActive' : 'focus' ]();
if ( CKEDITOR.env.ie && !( CKEDITOR.env.edge && CKEDITOR.env.version > 14 ) && this.getDocument().equals( CKEDITOR.document ) ) {
this.$.setActive();
} else {
this.$.focus();
}
} catch ( e ) {
// IE throws unspecified error when focusing editable after closing dialog opened on nested editable.
if ( !CKEDITOR.env.ie )
Expand Down Expand Up @@ -872,6 +883,23 @@
}, null, null, -1 );
}

// [Edge] This is the other part of the workaround for Edge which restores saved
// scrollTop value and removes listener which is not needed anymore. (#14825)
if ( CKEDITOR.env.edge && CKEDITOR.env.version > 14 ) {

var fixScrollOnFocus = function() {
var editable = editor.editable();

if ( editor._.previousScrollTop != null && editable.getDocument().equals( CKEDITOR.document ) ) {
editable.$.scrollTop = editor._.previousScrollTop;
editor._.previousScrollTop = null;
this.removeListener( 'scroll', fixScrollOnFocus );
}
};

this.on( 'scroll', fixScrollOnFocus );
}

// Register to focus manager.
editor.focusManager.add( this );

Expand Down
40 changes: 40 additions & 0 deletions tests/tickets/14825/1.js
@@ -0,0 +1,40 @@
/* bender-tags: 14825 */

( function() {
'use strict';

bender.editors = {
divarea: {
name: 'divarea',
startupData: '<p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p><p>Paragraph 4</p><p>Paragraph 5</p><p>Paragraph 6</p>',
config: {
extraPlugins: 'divarea',
width: '100px',
height: '100px'
}
}
};

bender.test( {
'test scroll position after focusing scrolled editor': function() {
if ( !( CKEDITOR.env.edge && CKEDITOR.env.version > 14 ) ) {
assert.ignore();
}

var editor = this.editors.divarea,
editable = editor.editable();

assert.areSame( 0, editable.$.scrollTop, 'Initial scrollTop is 0.' );

editable.find( 'p' ).getItem( 3 ).scrollIntoView();

var currentScrollTop = editable.$.scrollTop;
assert.isTrue( currentScrollTop > 0, 'Editor was scrolled successfully.' );

editor.focus();
wait( function() {
assert.areSame( currentScrollTop, editable.$.scrollTop, 'Editor scrollTop value did not change after focus.' );
}, 100 );
}
} );
} )();

0 comments on commit 3f95046

Please sign in to comment.