From 01a5fbd22596ab63191c44cb950b8291a22126f7 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 1 Aug 2017 15:17:38 +0200 Subject: [PATCH 1/2] Scroll the editing document to the selection after the content is pasted. --- src/clipboard.js | 2 ++ tests/clipboard.js | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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 38c7be9..50d80bf 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.create( { @@ -33,6 +33,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', () => {} ); } ); } ); @@ -215,6 +219,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' ); From 938da8c29ee2614696ed0c22f339fbd4ed39023c Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 10 Aug 2017 10:58:17 +0200 Subject: [PATCH 2/2] Tests: Updated stubs to the latest Sinon API. --- tests/clipboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clipboard.js b/tests/clipboard.js index a69be0b..8dfd36e 100644 --- a/tests/clipboard.js +++ b/tests/clipboard.js @@ -37,7 +37,7 @@ describe( 'Clipboard feature', () => { // 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', () => {} ); + scrollSpy = sinon.stub( editingView, 'scrollToTheSelection' ); } ); } );