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

Commit

Permalink
Merge pull request #27 from ckeditor/t/ckeditor5-table/126
Browse files Browse the repository at this point in the history
Other: Make `BlockQuoteCommand` wrap only top-most blocks.
  • Loading branch information
scofalik authored Jan 3, 2019
2 parents 65cca41 + 79b0f40 commit 17c9d3b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions src/blockquotecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ 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.
*
* @fires execute
*/
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 ) {
Expand All @@ -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 ) );
Expand Down
51 changes: 50 additions & 1 deletion tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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>'
);
} );
} );
} );

0 comments on commit 17c9d3b

Please sign in to comment.