8
0
Pārlūkot izejas kodu

Enable media embed command when selected media is in a table cell

Paweł Kwaśnik 5 gadi atpakaļ
vecāks
revīzija
ec85425388

+ 3 - 3
packages/ckeditor5-media-embed/src/mediaembedcommand.js

@@ -30,12 +30,12 @@ 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 ) {
+		if ( parent.isEmpty && model.schema.isBlock( parent ) ) {
 			parent = parent.parent;
 		}
 

+ 0 - 1
packages/ckeditor5-media-embed/src/mediaembedediting.js

@@ -171,7 +171,6 @@ export default class MediaEmbedEditing extends Plugin {
 			isObject: true,
 			isBlock: true,
 			allowWhere: '$block',
-			allowIn: 'tableRow',
 			allowAttributes: [ 'url' ]
 		} );
 

+ 23 - 0
packages/ckeditor5-media-embed/tests/insertmediacommand.js

@@ -50,6 +50,29 @@ describe( 'MediaEmbedCommand', () => {
 			expect( command.isEnabled ).to.be.true;
 		} );
 
+		it( 'should be true if a media is selected in 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( 'p', { allowIn: 'tableCell' } );
+			model.schema.extend( 'media', { allowIn: 'p' } );
+
+			setData( model, '<table><tableRow><tableCell><p>[<media></media>]</p></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' } );