Преглед изворни кода

Added AttributeCommand to bold.

Szymon Kupś пре 9 година
родитељ
комит
8f8fefbcd1

+ 14 - 5
packages/ckeditor5-basic-styles/src/boldengine.js

@@ -8,6 +8,9 @@
 import Feature from '../feature.js';
 import Feature from '../feature.js';
 import BuildModelConverterFor from '../engine/conversion/model-converter-builder.js';
 import BuildModelConverterFor from '../engine/conversion/model-converter-builder.js';
 import BuildViewConverterFor from '../engine/conversion/view-converter-builder.js';
 import BuildViewConverterFor from '../engine/conversion/view-converter-builder.js';
+import AttributeCommand from '../command/attributecommand.js';
+
+const BOLD_ATTRIBUTE = 'bold';
 
 
 export default class BoldEngine extends Feature {
 export default class BoldEngine extends Feature {
 	init() {
 	init() {
@@ -17,18 +20,24 @@ export default class BoldEngine extends Feature {
 		const data = editor.data;
 		const data = editor.data;
 
 
 		// Schema.
 		// Schema.
-		schema.allow( { name: '$inline', attributes: [ 'bold' ], inside: '$block' } );
+		schema.allow( { name: '$inline', attributes: [ BOLD_ATTRIBUTE ] } );
 
 
-		// Build converter from model to view for data and editing pipelines.
+		// Build converter from model to view for data pipeline.
+		// TODO: Converter for editing pipeline.
 		BuildModelConverterFor( data.modelToView )
 		BuildModelConverterFor( data.modelToView )
-			.fromAttribute( 'bold' )
+			.fromAttribute( BOLD_ATTRIBUTE )
 			.toElement( 'strong' );
 			.toElement( 'strong' );
 
 
-		// Build converter from view to model for data and editing pipelines.
+		// Build converter from view to model for data pipeline.
+		// TODO: Converter for editing pipeline.
 		BuildViewConverterFor( data.viewToModel )
 		BuildViewConverterFor( data.viewToModel )
 			.fromElement( 'strong' )
 			.fromElement( 'strong' )
 			.fromElement( 'b' )
 			.fromElement( 'b' )
 			.fromAttribute( 'style', { 'font-weight': 'bold' } )
 			.fromAttribute( 'style', { 'font-weight': 'bold' } )
-			.toAttribute( 'bold', true );
+			.toAttribute( BOLD_ATTRIBUTE, true );
+
+		// Command.
+		const command = new AttributeCommand( editor, BOLD_ATTRIBUTE );
+		editor.commands.set( BOLD_ATTRIBUTE, command );
 	}
 	}
 }
 }

+ 10 - 2
packages/ckeditor5-basic-styles/tests/boldengine.js

@@ -11,6 +11,7 @@ import StandardCreator from '/ckeditor5/creator/standardcreator.js';
 import { getData } from '/tests/engine/_utils/model.js';
 import { getData } from '/tests/engine/_utils/model.js';
 import BuildModelConverterFor from '/ckeditor5/engine/conversion/model-converter-builder.js';
 import BuildModelConverterFor from '/ckeditor5/engine/conversion/model-converter-builder.js';
 import BuildViewConverterFor from '/ckeditor5/engine/conversion/view-converter-builder.js';
 import BuildViewConverterFor from '/ckeditor5/engine/conversion/view-converter-builder.js';
+import AttributeCommand from '/ckeditor5/command/attributecommand.js';
 
 
 describe( 'BoldEngine', () => {
 describe( 'BoldEngine', () => {
 	let editor, document;
 	let editor, document;
@@ -45,7 +46,14 @@ describe( 'BoldEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( document.schema.check( { name: '$inline', attributes: [ 'bold' ], inside: '$block' } ) ).to.be.true;
+		expect( document.schema.check( { name: '$inline', attributes: [ 'bold' ] } ) ).to.be.true;
+	} );
+
+	it( 'should register bold command', () => {
+		expect( editor.commands.has( 'bold' ) ).to.be.true;
+		const command = editor.commands.get( 'bold' );
+		expect( command ).to.be.instanceOf( AttributeCommand );
+		expect( command.attributeKey ).to.equal( 'bold' );
 	} );
 	} );
 
 
 	it( 'should convert <strong> to bold attribute', () => {
 	it( 'should convert <strong> to bold attribute', () => {
@@ -63,7 +71,7 @@ describe( 'BoldEngine', () => {
 	} );
 	} );
 
 
 	it( 'should convert font-weight:bold to bold attribute', () => {
 	it( 'should convert font-weight:bold to bold attribute', () => {
-		editor.setData( '<p style="font-weight: bold;">foobar</p>' );
+		editor.setData( '<p><span style="font-weight: bold;">foobar</span></p>' );
 
 
 		expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
 		expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
 		expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
 		expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );