8
0
Просмотр исходного кода

Third batch of changes aligning schema use to the new API.

Piotrek Koszuliński 8 лет назад
Родитель
Сommit
c54fae23eb
2 измененных файлов с 25 добавлено и 2 удалено
  1. 1 1
      packages/ckeditor5-list/src/listcommand.js
  2. 24 1
      packages/ckeditor5-list/tests/listcommand.js

+ 1 - 1
packages/ckeditor5-list/src/listcommand.js

@@ -307,5 +307,5 @@ function _fixType( blocks, isBackward, lowestIndent ) {
 // @param {module:engine/model/schema~Schema} schema The schema of the document.
 // @param {module:engine/model/schema~Schema} schema The schema of the document.
 // @returns {Boolean}
 // @returns {Boolean}
 function checkCanBecomeListItem( block, schema ) {
 function checkCanBecomeListItem( block, schema ) {
-	return schema.checkChild( block.parent, 'listItem' );
+	return schema.checkChild( block.parent, 'listItem' ) && !schema.isObject( block );
 }
 }

+ 24 - 1
packages/ckeditor5-list/tests/listcommand.js

@@ -252,7 +252,7 @@ describe( 'ListCommand', () => {
 				} );
 				} );
 
 
 				// https://github.com/ckeditor/ckeditor5-list/issues/62
 				// https://github.com/ckeditor/ckeditor5-list/issues/62
-				it( 'should not rename blocks which cannot become listItems', () => {
+				it( 'should not rename blocks which cannot become listItems (list item is not allowed in their parent)', () => {
 					model.schema.register( 'restricted' );
 					model.schema.register( 'restricted' );
 					model.schema.extend( 'restricted', { allowIn: '$root' } );
 					model.schema.extend( 'restricted', { allowIn: '$root' } );
 					model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
 					model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
@@ -276,6 +276,29 @@ describe( 'ListCommand', () => {
 					);
 					);
 				} );
 				} );
 
 
+				it( 'should not rename blocks which cannot become listItems (block is an object)', () => {
+					model.schema.register( 'image', {
+						isBlock: true,
+						isObject: true,
+						allowIn: '$root'
+					} );
+
+					setData(
+						model,
+						'<paragraph>a[bc</paragraph>' +
+						'<image></image>' +
+						'<paragraph>de]f</paragraph>'
+					);
+
+					command.execute();
+
+					expect( getData( model ) ).to.equal(
+						'<listItem indent="0" type="bulleted">a[bc</listItem>' +
+						'<image></image>' +
+						'<listItem indent="0" type="bulleted">de]f</listItem>'
+					);
+				} );
+
 				it( 'should rename closest block to listItem and set correct attributes', () => {
 				it( 'should rename closest block to listItem and set correct attributes', () => {
 					// From first paragraph to second paragraph.
 					// From first paragraph to second paragraph.
 					// Command value=false, we are turning on list items.
 					// Command value=false, we are turning on list items.