Kaynağa Gözat

Scroll the editing document to the selection after the content is pasted.

Aleksander Nowodzinski 8 yıl önce
ebeveyn
işleme
ffbc9d4ff4

+ 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.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': '<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' );