Skip to content

Commit

Permalink
Merge branch 't/14894' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Comandeer committed Feb 7, 2017
2 parents f8d2136 + 3177361 commit af78e85
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -17,6 +17,7 @@ Fixed Issues:
* [#11956](http://dev.ckeditor.com/ticket/11956): [Blink, IE] Fixed: [Link](http://ckeditor.com/addon/link) dialog does not open on a double click on the second word of the link with background color or other styles.
* [#10472](http://dev.ckeditor.com/ticket/10472): Fixed: Unable to use [Table Resize](http://ckeditor.com/addon/tableresize) on table's header and footer.
* [#16777](https://dev.ckeditor.com/ticket/16777): [Edge] Fixed: [Clipboard](http://ckeditor.com/addon/clipboard) plugin doesn't allow to drop widgets into editor.
* [#14894](https://dev.ckeditor.com/ticket/14894): [Chrome] Fixed: Editor scrolls to top after focusing or when a dialog is opened.

## CKEditor 4.6.2

Expand Down
10 changes: 9 additions & 1 deletion core/editable.js
Expand Up @@ -87,7 +87,15 @@
if ( CKEDITOR.env.ie && !( CKEDITOR.env.edge && CKEDITOR.env.version > 14 ) && this.getDocument().equals( CKEDITOR.document ) ) {
this.$.setActive();
} else {
this.$.focus();
// We have no control over exactly what happens when the native `focus` method is called,
// so save the scroll position and restore it later.
if ( CKEDITOR.env.chrome ) {
var scrollPos = this.$.scrollTop;
this.$.focus();
this.$.scrollTop = scrollPos;
} else {
this.$.focus();
}
}
} catch ( e ) {
// IE throws unspecified error when focusing editable after closing dialog opened on nested editable.
Expand Down
55 changes: 55 additions & 0 deletions tests/core/editable/manual/scrollandfocus.html
@@ -0,0 +1,55 @@
<textarea name="editor1">
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
</textarea>
<hr />
<textarea name="editor2">
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
</textarea>
<script type="text/javascript">
if ( !CKEDITOR.env.chrome ) {
bender.ignore();
}

CKEDITOR.replace( 'editor1' );
CKEDITOR.replace( 'editor2' );
</script>
17 changes: 17 additions & 0 deletions tests/core/editable/manual/scrollandfocus.md
@@ -0,0 +1,17 @@
@bender-tags: 4.7.0, tc, 14894
@bender-ui: collapsed
@bender-ckeditor-plugins: clipboard, contextmenu, toolbar, wysiwygarea, link

## Test scenario

For each editor:
1. Scroll it without focusing.
2. Open the link dialog.

## Expected result

Scroll position remains unchanged.

## Unexpected

Editor scroll position is moved to top.
31 changes: 30 additions & 1 deletion tests/core/editable/misc.js
Expand Up @@ -9,6 +9,13 @@ bender.editors = {
config: {
allowedContent: true
}
},
scrollable: {
name: 'editor2',
creator: 'replace',
config: {
height: 300
}
}
};

Expand Down Expand Up @@ -96,5 +103,27 @@ bender.test( {

assert.areSame( 'foo', editor.getSelection().getSelectedText(), 'Selection has not been changed' );
} );
},

'test scroll editable and focus': function() {
if ( !CKEDITOR.env.chrome ) {
assert.ignore();
}

var bot = this.editorBots.scrollable,
editable = this.editors.scrollable.editable();

bot.setData( '<p>Test</p><p>Test</p><p>Test</p><p>Test</p>' +
'<p>Test</p><p>Test</p><p>Test</p><p>Test</p>' +
'<p>Test</p><p>Test</p><p>Test</p><p>Test</p>' +
'<p>Test</p><p>Test</p><p>Test</p><p>Test</p>' +
'<p>Test</p><p>Test</p><p>Test</p><p>Test</p>', function() {
var scrollPos = 100;

editable.$.scrollTop = scrollPos;
editable.focus();

assert.areSame( scrollPos, editable.$.scrollTop );
} );
}
} );
} );

0 comments on commit af78e85

Please sign in to comment.