Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge branch t/ckedtor5-engine/660 to master
Browse files Browse the repository at this point in the history
Feature: Viewport will be scrolled to the selection upon user input. See ckeditor/ckeditor5-engine#660.
  • Loading branch information
Reinmar committed Aug 15, 2017
2 parents 64e46f5 + 938da8c commit 9a0e20f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export default class Clipboard extends Plugin {
content = this._htmlDataProcessor.toView( content );

this.fire( 'inputTransformation', { content } );

editingView.scrollToTheSelection();
}, { priority: 'low' } );

this.listenTo( this, 'inputTransformation', ( evt, data ) => {
Expand Down
21 changes: 20 additions & 1 deletion tests/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ViewDocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfr
import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';

describe( 'Clipboard feature', () => {
let editor, editingView, clipboardPlugin;
let editor, editingView, clipboardPlugin, scrollSpy;

beforeEach( () => {
return VirtualTestEditor
Expand All @@ -34,6 +34,10 @@ describe( 'Clipboard feature', () => {
editor = newEditor;
editingView = editor.editing.view;
clipboardPlugin = editor.plugins.get( 'Clipboard' );

// VirtualTestEditor has no DOM, so this method must be stubbed for all tests.
// Otherwise it will throw as it accesses the DOM to do its job.
scrollSpy = sinon.stub( editingView, 'scrollToTheSelection' );
} );
} );

Expand Down Expand Up @@ -216,6 +220,21 @@ describe( 'Clipboard feature', () => {
expect( spy.callCount ).to.equal( 0 );
} );

it( 'scrolls the editing document to the selection after the pasted content is inserted', () => {
const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
const inputTransformationSpy = sinon.spy();

clipboardPlugin.on( 'inputTransformation', inputTransformationSpy );

editingView.fire( 'clipboardInput', {
dataTransfer: dataTransferMock,
content: new ViewDocumentFragment()
} );

sinon.assert.calledOnce( scrollSpy );
sinon.assert.callOrder( inputTransformationSpy, scrollSpy );
} );

it( 'uses low priority observer for the clipboardInput event', () => {
const dataTransferMock = createDataTransfer( { 'text/html': 'x' } );
const spy = sinon.stub( editor.data, 'insertContent' );
Expand Down

0 comments on commit 9a0e20f

Please sign in to comment.