8
0
Просмотр исходного кода

Merge branch t/ckedtor5-engine/660 to master

Feature: Viewport will be scrolled to the selection upon user input. See ckeditor/ckeditor5-engine#660.
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
e12981b656

+ 2 - 0
packages/ckeditor5-clipboard/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 ) => {

+ 20 - 1
packages/ckeditor5-clipboard/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': '<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' );