Bläddra i källkod

Merge pull request #27 from ckeditor/t/ckeditor5-table/126

Other: Make `BlockQuoteCommand` wrap only top-most blocks.
Szymon Cofalik 7 år sedan
förälder
incheckning
0435746c80

+ 1 - 0
packages/ckeditor5-block-quote/package.json

@@ -24,6 +24,7 @@
     "@ckeditor/ckeditor5-image": "^12.0.0",
     "@ckeditor/ckeditor5-list": "^11.0.3",
     "@ckeditor/ckeditor5-paragraph": "^10.0.4",
+    "@ckeditor/ckeditor5-table": "^11.0.0",
     "@ckeditor/ckeditor5-typing": "^11.0.2",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^1.0.9",

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

@@ -34,7 +34,7 @@ export default class BlockQuoteCommand extends Command {
 	}
 
 	/**
-	 * Executes the command. When the command {@link #value is on}, all block quotes within
+	 * Executes the command. When the command {@link #value is on}, all top-most block quotes within
 	 * the selection will be removed. If it is off, all selected blocks will be wrapped with
 	 * a block quote.
 	 *
@@ -42,9 +42,10 @@ export default class BlockQuoteCommand extends Command {
 	 */
 	execute() {
 		const model = this.editor.model;
-		const doc = model.document;
 		const schema = model.schema;
-		const blocks = Array.from( doc.selection.getSelectedBlocks() );
+		const selection = model.document.selection;
+
+		const blocks = Array.from( selection.getTopMostBlocks() );
 
 		model.change( writer => {
 			if ( this.value ) {
@@ -68,7 +69,9 @@ export default class BlockQuoteCommand extends Command {
 	 * @returns {Boolean} The current value.
 	 */
 	_getValue() {
-		const firstBlock = first( this.editor.model.document.selection.getSelectedBlocks() );
+		const selection = this.editor.model.document.selection;
+
+		const firstBlock = first( selection.getTopMostBlocks() );
 
 		// In the current implementation, the block quote must be an immediate parent of a block element.
 		return !!( firstBlock && findQuote( firstBlock ) );

+ 50 - 1
packages/ckeditor5-block-quote/tests/integration.js

@@ -13,6 +13,7 @@ import List from '@ckeditor/ckeditor5-list/src/list';
 import Enter from '@ckeditor/ckeditor5-enter/src/enter';
 import Delete from '@ckeditor/ckeditor5-typing/src/delete';
 import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import Table from '@ckeditor/ckeditor5-table/src/table';
 
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import {
@@ -30,7 +31,7 @@ describe( 'BlockQuote integration', () => {
 
 		return ClassicTestEditor
 			.create( element, {
-				plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete, Heading ]
+				plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete, Heading, Table ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -418,4 +419,52 @@ describe( 'BlockQuote integration', () => {
 			);
 		} );
 	} );
+
+	describe( 'compatibility with tables', () => {
+		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>'
+			);
+		} );
+
+		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>]'
+			);
+		} );
+
+		it( 'wraps table cell paragraph', () => {
+			setModelData( model, '<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>' );
+
+			editor.execute( 'blockQuote' );
+
+			expect( getModelData( model ) ).to.equal(
+				'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
+			);
+		} );
+
+		it( 'unwraps table cell paragraph', () => {
+			setModelData(
+				model,
+				'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
+			);
+
+			editor.execute( 'blockQuote' );
+
+			expect( getModelData( model ) ).to.equal(
+				'<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>'
+			);
+		} );
+	} );
 } );