8
0
Maciej Gołaszewski 6 лет назад
Родитель
Сommit
0cdcca9fa2

+ 3 - 0
packages/ckeditor5-indent/src/indentblock.js

@@ -46,8 +46,11 @@ export default class IndentBlock extends Plugin {
 		const config = editor.config.get( 'indentBlock' );
 
 		// TODO: better features inclusion
+		// CKE4: context: { div: 1, dl: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1, ul: 1, ol: 1, p: 1, pre: 1, table: 1 },
 		schema.extend( 'paragraph', { allowAttributes: 'indent' } );
 		schema.extend( 'heading1', { allowAttributes: 'indent' } );
+		schema.extend( 'heading2', { allowAttributes: 'indent' } );
+		schema.extend( 'heading3', { allowAttributes: 'indent' } );
 
 		const classes = config.classes;
 

+ 0 - 3
packages/ckeditor5-indent/src/indentblockcommand.js

@@ -51,9 +51,6 @@ export default class IndentBlockCommand extends Command {
 
 		model.change( writer => {
 			for ( const item of itemsToChange ) {
-				// eslint-disable-next-line no-undef
-				console.log( 'indent block', item );
-
 				const currentIndent = item.getAttribute( 'indent' );
 				let newIndent;
 

+ 66 - 2
packages/ckeditor5-indent/tests/indentblock.js

@@ -50,8 +50,10 @@ describe( 'IndentBlock', () => {
 			.then( newEditor => {
 				model = newEditor.model;
 
-				expect( model.schema.checkAttribute( [ 'heading1' ], 'indent' ) ).to.be.true;
 				expect( model.schema.checkAttribute( [ 'paragraph' ], 'indent' ) ).to.be.true;
+				expect( model.schema.checkAttribute( [ 'heading1' ], 'indent' ) ).to.be.true;
+				expect( model.schema.checkAttribute( [ 'heading2' ], 'indent' ) ).to.be.true;
+				expect( model.schema.checkAttribute( [ 'heading3' ], 'indent' ) ).to.be.true;
 			} );
 	} );
 
@@ -64,6 +66,16 @@ describe( 'IndentBlock', () => {
 			} );
 	} );
 
+	describe( 'config', () => {
+		describe( 'default value', () => {
+			it( 'should be set', () => {
+				return createTestEditor().then( editor => {
+					expect( editor.config.get( 'indentBlock' ) ).to.deep.equal( { offset: 1, unit: 'em', classes: [] } );
+				} );
+			} );
+		} );
+	} );
+
 	describe( 'conversion', () => {
 		describe( 'using offset', () => {
 			beforeEach( () => {
@@ -75,7 +87,7 @@ describe( 'IndentBlock', () => {
 					} );
 			} );
 
-			it( 'should convert margin-left to indent attribute', () => {
+			it( 'should convert margin-left to indent attribute (known offset)', () => {
 				editor.setData( '<p style="margin-left:50px">foo</p>' );
 
 				const paragraph = doc.getRoot().getChild( 0 );
@@ -87,6 +99,32 @@ describe( 'IndentBlock', () => {
 				expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
 					.to.equal( '<p style="margin-left:50px">foo</p>' );
 			} );
+
+			it( 'should convert margin-left to indent attribute (any offset)', () => {
+				editor.setData( '<p style="margin-left:42em">foo</p>' );
+
+				const paragraph = doc.getRoot().getChild( 0 );
+
+				expect( paragraph.hasAttribute( 'indent' ) ).to.be.true;
+				expect( paragraph.getAttribute( 'indent' ) ).to.equal( '42em' );
+
+				expect( editor.getData() ).to.equal( '<p style="margin-left:42em;">foo</p>' );
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+					.to.equal( '<p style="margin-left:42em">foo</p>' );
+			} );
+
+			it( 'should not convert class to indent attribute', () => {
+				editor.setData( '<p class="indent-1">foo</p>' );
+
+				const paragraph = doc.getRoot().getChild( 0 );
+
+				expect( paragraph.hasAttribute( 'indent' ) ).to.be.false;
+
+				const expectedView = '<p>foo</p>';
+
+				expect( editor.getData() ).to.equal( expectedView );
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
+			} );
 		} );
 
 		describe( 'using classes', () => {
@@ -115,6 +153,32 @@ describe( 'IndentBlock', () => {
 				expect( editor.getData() ).to.equal( expectedView );
 				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
 			} );
+
+			it( 'should not convert unknown class to indent attribute', () => {
+				editor.setData( '<p class="indent-7">foo</p>' );
+
+				const paragraph = doc.getRoot().getChild( 0 );
+
+				expect( paragraph.hasAttribute( 'indent' ) ).to.be.false;
+
+				const expectedView = '<p>foo</p>';
+
+				expect( editor.getData() ).to.equal( expectedView );
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
+			} );
+
+			it( 'should not convert margin-left to indent attribute (known offset)', () => {
+				editor.setData( '<p style="margin-left:50px">foo</p>' );
+
+				const paragraph = doc.getRoot().getChild( 0 );
+
+				expect( paragraph.hasAttribute( 'indent' ) ).to.be.false;
+
+				const expectedView = '<p>foo</p>';
+
+				expect( editor.getData() ).to.equal( expectedView );
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
+			} );
 		} );
 	} );