Răsfoiți Sursa

Blockquote should quote an image inside a table cell.

Maciej Gołaszewski 7 ani în urmă
părinte
comite
7d9585acbb

+ 15 - 3
packages/ckeditor5-block-quote/src/blockquotecommand.js

@@ -45,7 +45,15 @@ export default class BlockQuoteCommand extends Command {
 		const schema = model.schema;
 		const schema = model.schema;
 		const selection = model.document.selection;
 		const selection = model.document.selection;
 
 
-		const blocks = Array.from( selection.getTopMostBlocks() );
+		const selElem = selection.getSelectedElement();
+
+		let blocks;
+
+		if ( selElem ) {
+			blocks = [ selElem ];
+		} else {
+			blocks = Array.from( selection.getTopMostBlocks() );
+		}
 
 
 		model.change( writer => {
 		model.change( writer => {
 			if ( this.value ) {
 			if ( this.value ) {
@@ -71,10 +79,14 @@ export default class BlockQuoteCommand extends Command {
 	_getValue() {
 	_getValue() {
 		const selection = this.editor.model.document.selection;
 		const selection = this.editor.model.document.selection;
 
 
-		const firstBlock = first( selection.getTopMostBlocks() );
+		let selectedBlock = selection.getSelectedElement();
+
+		if ( !selectedBlock ) {
+			selectedBlock = first( selection.getTopMostBlocks() );
+		}
 
 
 		// In the current implementation, the block quote must be an immediate parent of a block element.
 		// In the current implementation, the block quote must be an immediate parent of a block element.
-		return !!( firstBlock && findQuote( firstBlock ) );
+		return !!( selectedBlock && findQuote( selectedBlock ) );
 	}
 	}
 
 
 	/**
 	/**

+ 42 - 2
packages/ckeditor5-block-quote/tests/integration.js

@@ -444,7 +444,7 @@ describe( 'BlockQuote integration', () => {
 			);
 			);
 		} );
 		} );
 
 
-		it( 'wraps table cell paragraph', () => {
+		it( 'wraps paragraph in table cell', () => {
 			setModelData( model, '<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>' );
 			setModelData( model, '<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>' );
 
 
 			editor.execute( 'blockQuote' );
 			editor.execute( 'blockQuote' );
@@ -454,7 +454,7 @@ describe( 'BlockQuote integration', () => {
 			);
 			);
 		} );
 		} );
 
 
-		it( 'unwraps table cell paragraph', () => {
+		it( 'unwraps paragraph in table cell', () => {
 			setModelData(
 			setModelData(
 				model,
 				model,
 				'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
 				'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
@@ -466,5 +466,45 @@ describe( 'BlockQuote integration', () => {
 				'<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>'
 				'<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>'
 			);
 			);
 		} );
 		} );
+
+		it( 'wraps image in table cell', () => {
+			setModelData( model,
+				'<table>' +
+					'<tableRow>' +
+						'<tableCell>[<image><caption>foo</caption></image>]</tableCell>' +
+				'	</tableRow>' +
+				'</table>'
+			);
+
+			editor.execute( 'blockQuote' );
+
+			expect( getModelData( model ) ).to.equal(
+				'<table>' +
+					'<tableRow>' +
+						'<tableCell><blockQuote>[<image><caption>foo</caption></image>]</blockQuote></tableCell>' +
+					'</tableRow>' +
+				'</table>'
+			);
+		} );
+
+		it( 'unwraps image in table cell', () => {
+			setModelData( model,
+				'<table>' +
+					'<tableRow>' +
+						'<tableCell><blockQuote>[<image><caption>foo</caption></image>]</blockQuote></tableCell>' +
+					'</tableRow>' +
+				'</table>'
+			);
+
+			editor.execute( 'blockQuote' );
+
+			expect( getModelData( model ) ).to.equal(
+				'<table>' +
+					'<tableRow>' +
+						'<tableCell>[<image><caption>foo</caption></image>]</tableCell>' +
+					'</tableRow>' +
+				'</table>'
+			);
+		} );
 	} );
 	} );
 } );
 } );