Преглед на файлове

Revert "SAlways scroll the viewport to the selection when the BlockQuoteCommand gets executed."

This reverts commit 8c9ec706ae0106e71e73a645889cc4081d8fca51.
Aleksander Nowodzinski преди 8 години
родител
ревизия
b84f17edb0

+ 1 - 0
packages/ckeditor5-block-quote/src/blockquote.js

@@ -84,6 +84,7 @@ export default class BlockQuote extends Plugin {
 
 			if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) {
 				this.editor.execute( 'blockQuote' );
+				this.editor.editing.view.scrollToTheSelection();
 
 				data.preventDefault();
 				evt.stop();

+ 1 - 4
packages/ckeditor5-block-quote/src/blockquotecommand.js

@@ -47,8 +47,7 @@ export default class BlockQuoteCommand extends Command {
 	 * A new batch will be created if this option is not set.
 	 */
 	execute( options = {} ) {
-		const editor = this.editor;
-		const doc = editor.document;
+		const doc = this.editor.document;
 		const schema = doc.schema;
 		const batch = options.batch || doc.batch();
 		const blocks = Array.from( doc.selection.getSelectedBlocks() );
@@ -65,8 +64,6 @@ export default class BlockQuoteCommand extends Command {
 
 				this._applyQuote( batch, blocksToQuote );
 			}
-
-			editor.editing.view.scrollToTheSelection();
 		} );
 	}
 

+ 0 - 42
packages/ckeditor5-block-quote/tests/blockquotecommand.js

@@ -141,14 +141,6 @@ describe( 'BlockQuoteCommand', () => {
 	} );
 
 	describe( 'execute()', () => {
-		let scrollToTheSelectionStub;
-
-		beforeEach( () => {
-			// 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.
-			scrollToTheSelectionStub = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} );
-		} );
-
 		describe( 'applying quote', () => {
 			it( 'should wrap a single block', () => {
 				setModelData(
@@ -439,23 +431,6 @@ describe( 'BlockQuoteCommand', () => {
 					'</blockQuote>'
 				);
 			} );
-
-			it( 'should scroll the viewport to the selection', () => {
-				setModelData( doc, '<widget>[xx]</widget>' );
-
-				editor.execute( 'blockQuote' );
-				sinon.assert.notCalled( scrollToTheSelectionStub );
-
-				setModelData(
-					doc,
-					'<paragraph>abc</paragraph>' +
-					'<paragraph>x[]x</paragraph>' +
-					'<paragraph>def</paragraph>'
-				);
-
-				editor.execute( 'blockQuote' );
-				sinon.assert.calledOnce( scrollToTheSelectionStub );
-			} );
 		} );
 
 		describe( 'removing quote', () => {
@@ -616,23 +591,6 @@ describe( 'BlockQuoteCommand', () => {
 					'<blockquote><p>ghi</p></blockquote>'
 				);
 			} );
-
-			it( 'should scroll the viewport to the selections', () => {
-				setModelData( doc, '<widget>[xx]</widget>' );
-
-				editor.execute( 'blockQuote' );
-				sinon.assert.notCalled( scrollToTheSelectionStub );
-
-				setModelData(
-					doc,
-					'<paragraph>abc</paragraph>' +
-					'<blockQuote><paragraph>x[]x</paragraph></blockQuote>' +
-					'<paragraph>def</paragraph>'
-				);
-
-				editor.execute( 'blockQuote' );
-				sinon.assert.calledOnce( scrollToTheSelectionStub );
-			} );
 		} );
 	} );
 } );

+ 17 - 0
packages/ckeditor5-block-quote/tests/integration.js

@@ -191,6 +191,23 @@ describe( 'BlockQuote', () => {
 				'<paragraph>x</paragraph>'
 			);
 		} );
+
+		it( 'scrolls the view document to the selection after the command is executed', () => {
+			const data = fakeEventData();
+			const execSpy = sinon.spy( editor, 'execute' );
+			const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} );
+
+			setModelData( doc,
+				'<paragraph>x</paragraph>' +
+				'<blockQuote><paragraph>a</paragraph><paragraph>[]</paragraph></blockQuote>' +
+				'<paragraph>x</paragraph>'
+			);
+
+			editor.editing.view.fire( 'enter', data );
+
+			sinon.assert.calledOnce( scrollSpy );
+			sinon.assert.callOrder( execSpy, scrollSpy );
+		} );
 	} );
 
 	describe( 'backspace key support', () => {