Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 17c9d3b

Browse files
authored
Merge pull request #27 from ckeditor/t/ckeditor5-table/126
Other: Make `BlockQuoteCommand` wrap only top-most blocks.
2 parents 65cca41 + 79b0f40 commit 17c9d3b

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@ckeditor/ckeditor5-image": "^12.0.0",
2525
"@ckeditor/ckeditor5-list": "^11.0.3",
2626
"@ckeditor/ckeditor5-paragraph": "^10.0.4",
27+
"@ckeditor/ckeditor5-table": "^11.0.0",
2728
"@ckeditor/ckeditor5-typing": "^11.0.2",
2829
"eslint": "^5.5.0",
2930
"eslint-config-ckeditor5": "^1.0.9",

src/blockquotecommand.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ export default class BlockQuoteCommand extends Command {
3434
}
3535

3636
/**
37-
* Executes the command. When the command {@link #value is on}, all block quotes within
37+
* Executes the command. When the command {@link #value is on}, all top-most block quotes within
3838
* the selection will be removed. If it is off, all selected blocks will be wrapped with
3939
* a block quote.
4040
*
4141
* @fires execute
4242
*/
4343
execute() {
4444
const model = this.editor.model;
45-
const doc = model.document;
4645
const schema = model.schema;
47-
const blocks = Array.from( doc.selection.getSelectedBlocks() );
46+
const selection = model.document.selection;
47+
48+
const blocks = Array.from( selection.getTopMostBlocks() );
4849

4950
model.change( writer => {
5051
if ( this.value ) {
@@ -68,7 +69,9 @@ export default class BlockQuoteCommand extends Command {
6869
* @returns {Boolean} The current value.
6970
*/
7071
_getValue() {
71-
const firstBlock = first( this.editor.model.document.selection.getSelectedBlocks() );
72+
const selection = this.editor.model.document.selection;
73+
74+
const firstBlock = first( selection.getTopMostBlocks() );
7275

7376
// In the current implementation, the block quote must be an immediate parent of a block element.
7477
return !!( firstBlock && findQuote( firstBlock ) );

tests/integration.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import List from '@ckeditor/ckeditor5-list/src/list';
1313
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
1414
import Delete from '@ckeditor/ckeditor5-typing/src/delete';
1515
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
16+
import Table from '@ckeditor/ckeditor5-table/src/table';
1617

1718
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
1819
import {
@@ -30,7 +31,7 @@ describe( 'BlockQuote integration', () => {
3031

3132
return ClassicTestEditor
3233
.create( element, {
33-
plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete, Heading ]
34+
plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete, Heading, Table ]
3435
} )
3536
.then( newEditor => {
3637
editor = newEditor;
@@ -418,4 +419,52 @@ describe( 'BlockQuote integration', () => {
418419
);
419420
} );
420421
} );
422+
423+
describe( 'compatibility with tables', () => {
424+
it( 'wraps whole table', () => {
425+
setModelData( model, '[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]' );
426+
427+
editor.execute( 'blockQuote' );
428+
429+
expect( getModelData( model ) ).to.equal(
430+
'<blockQuote>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]</blockQuote>'
431+
);
432+
} );
433+
434+
it( 'unwraps whole table', () => {
435+
setModelData(
436+
model,
437+
'<blockQuote>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]</blockQuote>'
438+
);
439+
440+
editor.execute( 'blockQuote' );
441+
442+
expect( getModelData( model ) ).to.equal(
443+
'[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]'
444+
);
445+
} );
446+
447+
it( 'wraps table cell paragraph', () => {
448+
setModelData( model, '<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>' );
449+
450+
editor.execute( 'blockQuote' );
451+
452+
expect( getModelData( model ) ).to.equal(
453+
'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
454+
);
455+
} );
456+
457+
it( 'unwraps table cell paragraph', () => {
458+
setModelData(
459+
model,
460+
'<table><tableRow><tableCell><blockQuote><paragraph>[]foo</paragraph></blockQuote></tableCell></tableRow></table>'
461+
);
462+
463+
editor.execute( 'blockQuote' );
464+
465+
expect( getModelData( model ) ).to.equal(
466+
'<table><tableRow><tableCell><paragraph>[]foo</paragraph></tableCell></tableRow></table>'
467+
);
468+
} );
469+
} );
421470
} );

0 commit comments

Comments
 (0)