diff --git a/src/clipboard.js b/src/clipboard.js index 1bbee53..4bc54d5 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -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 ) => { diff --git a/tests/clipboard.js b/tests/clipboard.js index 5c48468..8dfd36e 100644 --- a/tests/clipboard.js +++ b/tests/clipboard.js @@ -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 @@ -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' ); } ); } ); @@ -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': '
x
', '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' );