浏览代码

Fix removing blockquote from table.

Maciej Gołaszewski 7 年之前
父节点
当前提交
5cdcf874ba

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

@@ -76,8 +76,22 @@ export default class BlockQuoteCommand extends Command {
 	 * @returns {Boolean} The current value.
 	 */
 	_getValue() {
-		const firstBlock = first( this.editor.model.document.selection.getSelectedBlocks() );
+		const model = this.editor.model;
+		const schema = model.schema;
+
+		// TODO: Unify this with execute().
+		const selectedBlocks = Array.from( this.editor.model.document.selection.getSelectedBlocks() );
+
+		const blocks = selectedBlocks.filter( block => {
+			const parentBlock = findAncestorBlock( model.createPositionBefore( block ), schema );
+
+			// Filter out blocks that are nested in other selected blocks (like paragraphs in tables).
+			return !parentBlock || !selectedBlocks.includes( parentBlock );
+		} );
+
+		const firstBlock = blocks.shift();
 
+		// console.log( firstBlock );
 		// In the current implementation, the block quote must be an immediate parent of a block element.
 		return !!( firstBlock && findQuote( firstBlock ) );
 	}

+ 15 - 4
packages/ckeditor5-block-quote/tests/integration.js

@@ -421,15 +421,26 @@ describe( 'BlockQuote integration', () => {
 	} );
 
 	describe( 'compatibility with tables', () => {
-		it( 'wraps whole table in paragraph', () => {
+		it( 'wraps whole table', () => {
 			setModelData( model, '[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]' );
 
 			editor.execute( 'blockQuote' );
 
 			expect( getModelData( model ) ).to.equal(
-				'<blockQuote>' +
-				'[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]' +
-				'</blockQuote>'
+				'<blockQuote>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]</blockQuote>'
+			);
+		} );
+
+		it( 'unwraps whole table', () => {
+			setModelData(
+				model,
+				'<blockQuote>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]</blockQuote>'
+			);
+
+			editor.execute( 'blockQuote' );
+
+			expect( getModelData( model ) ).to.equal(
+				'[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]'
 			);
 		} );
 	} );