Skip to content

Commit

Permalink
Merge pull request #8216 from ckeditor/i/7604
Browse files Browse the repository at this point in the history
Fix (media-embed): Enable media embed command when selected media is in a table cell. Closes #7604.
  • Loading branch information
jodator authored Oct 8, 2020
2 parents 89775f9 + 404984c commit f36fcba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/ckeditor5-media-embed/src/mediaembedcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export default class MediaEmbedCommand extends Command {
const model = this.editor.model;
const selection = model.document.selection;
const schema = model.schema;
const position = selection.getFirstPosition();
const insertPosition = findOptimalInsertionPosition( selection, model );
const selectedMedia = getSelectedMediaModelWidget( selection );

let parent = position.parent;
let parent = insertPosition.parent;

if ( parent != parent.root ) {
// The model.insertContent() will remove empty parent (unless it is a $root or a limit).
if ( parent.isEmpty && !model.schema.isLimit( parent ) ) {
parent = parent.parent;
}

Expand Down Expand Up @@ -68,4 +69,3 @@ export default class MediaEmbedCommand extends Command {
}
}
}

22 changes: 22 additions & 0 deletions packages/ckeditor5-media-embed/tests/insertmediacommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ describe( 'MediaEmbedCommand', () => {
expect( command.isEnabled ).to.be.true;
} );

it( 'should be true if a media is selected in a table cell', () => {
model.schema.register( 'table', { allowIn: '$root', isLimit: true, isObject: true, isBlock: true } );
model.schema.register( 'tableRow', { allowIn: 'table', isLimit: true } );
model.schema.register( 'tableCell', { allowIn: 'tableRow', isLimit: true, isSelectable: true } );
model.schema.extend( 'media', { allowIn: 'tableCell' } );

setData( model, '<table><tableRow><tableCell>[<media></media>]</tableCell></tableRow></table>' );

expect( command.isEnabled ).to.be.true;
} );

it( 'should be true if in a table cell', () => {
model.schema.register( 'table', { allowIn: '$root', isLimit: true, isObject: true, isBlock: true } );
model.schema.register( 'tableRow', { allowIn: 'table', isLimit: true } );
model.schema.register( 'tableCell', { allowIn: 'tableRow', isLimit: true, isSelectable: true } );
model.schema.extend( '$block', { allowIn: 'tableCell' } );

setData( model, '<table><tableRow><tableCell><p>foo[]</p></tableCell></tableRow></table>' );

expect( command.isEnabled ).to.be.true;
} );

it( 'should be true when the selection directly in a block', () => {
model.schema.register( 'block', { inheritAllFrom: '$block' } );
model.schema.extend( '$text', { allowIn: 'block' } );
Expand Down

0 comments on commit f36fcba

Please sign in to comment.