ソースを参照

Other: Update Font Size feature to latest changes in engine.

Maciej Gołaszewski 8 年 前
コミット
bcabfff5cc

+ 9 - 11
packages/ckeditor5-font/src/fontsize/fontsizecommand.js

@@ -37,10 +37,10 @@ export default class FontSizeCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		const doc = this.editor.document;
+		const doc = this.editor.model.document;
 
 		this.value = doc.selection.getAttribute( 'fontSize' ) === this.fontSize;
-		this.isEnabled = doc.schema.checkAttributeInSelection( doc.selection, 'fontSize' );
+		this.isEnabled = this.editor.model.schema.checkAttributeInSelection( doc.selection, 'fontSize' );
 	}
 
 	/**
@@ -48,24 +48,22 @@ export default class FontSizeCommand extends Command {
 	 *
 	 * @protected
 	 * @param {Object} [options] Options for the executed command.
-	 * @param {module:engine/model/batch~Batch} [options.batch] A batch to collect all the change steps.
-	 * A new batch will be created if this option is not set.
 	 */
-	execute( options = {} ) {
-		const doc = this.editor.document;
-		const selection = doc.selection;
+	execute() {
+		const model = this.editor.model;
+		const document = model.document;
+		const selection = document.selection;
 
 		// Do not apply fontSize on collapsed selection.
 		if ( selection.isCollapsed ) {
 			return;
 		}
 
-		doc.enqueueChanges( () => {
-			const ranges = doc.schema.getValidRanges( selection.getRanges(), 'fontSize' );
-			const batch = options.batch || doc.batch();
+		model.change( writer => {
+			const ranges = model.schema.getValidRanges( selection.getRanges(), 'fontSize' );
 
 			for ( const range of ranges ) {
-				batch.setAttribute( 'fontSize', this.fontSize, range );
+				writer.setAttribute( 'fontSize', this.fontSize, range );
 			}
 		} );
 	}

+ 6 - 6
packages/ckeditor5-font/src/fontsize/fontsizeediting.js

@@ -9,8 +9,8 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import {
-	attributeElementToViewConverter,
-	viewToAttributeElementConverter
+	modelAttributeToViewAttributeElement,
+	viewToModelAttribute
 } from '@ckeditor/ckeditor5-engine/src/conversion/configurationdefinedconverters';
 
 /**
@@ -42,10 +42,10 @@ export default class FontSizeEditing extends Plugin {
 
 		for ( const item of this.configuredItems ) {
 			// Covert view to model.
-			viewToAttributeElementConverter( 'fontSize', item, [ data.viewToModel ] );
+			viewToModelAttribute( 'fontSize', item, [ data.viewToModel ] );
 
 			// Covert model to view.
-			attributeElementToViewConverter( 'fontSize', item, [ data.modelToView, editing.modelToView ] );
+			modelAttributeToViewAttributeElement( 'fontSize', item, [ data.modelToView, editing.modelToView ] );
 
 			// Add command.
 		}
@@ -81,9 +81,9 @@ export default class FontSizeEditing extends Plugin {
 		const editor = this.editor;
 
 		// Allow highlight attribute on all elements
-		editor.document.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$block' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$block' } );
 		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.document.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } );
 	}
 }
 

+ 15 - 15
packages/ckeditor5-font/tests/fontsize/fontsizecommand.js

@@ -10,20 +10,20 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'FontSizeCommand', () => {
-	let editor, doc, command;
+	let editor, model, command;
 
 	beforeEach( () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
-				doc = newEditor.document;
+				model = newEditor.model;
 				command = new FontSizeCommand( newEditor, 'text-huge' );
 				editor = newEditor;
 
 				editor.commands.add( 'fontSize', command );
 
-				doc.schema.registerItem( 'paragraph', '$block' );
+				model.schema.registerItem( 'paragraph', '$block' );
 
-				doc.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$block' } );
+				model.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$block' } );
 			} );
 	} );
 
@@ -38,13 +38,13 @@ describe( 'FontSizeCommand', () => {
 
 	describe( 'value', () => {
 		it( 'is set to true when selection is in text with fontSize attribute', () => {
-			setData( doc, '<paragraph><$text fontSize="text-huge">fo[]o</$text></paragraph>' );
+			setData( model, '<paragraph><$text fontSize="text-huge">fo[]o</$text></paragraph>' );
 
 			expect( command ).to.have.property( 'value', true );
 		} );
 
 		it( 'is undefined when selection is not in text with fontSize attribute', () => {
-			setData( doc, '<paragraph>fo[]o</paragraph>' );
+			setData( model, '<paragraph>fo[]o</paragraph>' );
 
 			expect( command ).to.have.property( 'value', false );
 		} );
@@ -52,7 +52,7 @@ describe( 'FontSizeCommand', () => {
 
 	describe( 'isEnabled', () => {
 		it( 'is true when selection is on text which can have fontSize added', () => {
-			setData( doc, '<paragraph>fo[]o</paragraph>' );
+			setData( model, '<paragraph>fo[]o</paragraph>' );
 
 			expect( command ).to.have.property( 'isEnabled', true );
 		} );
@@ -60,7 +60,7 @@ describe( 'FontSizeCommand', () => {
 
 	describe( 'execute()', () => {
 		it( 'should add fontSize attribute on selected text', () => {
-			setData( doc, '<paragraph>a[bc<$text fontSize="text-huge">fo]obar</$text>xyz</paragraph>' );
+			setData( model, '<paragraph>a[bc<$text fontSize="text-huge">fo]obar</$text>xyz</paragraph>' );
 
 			expect( command.value ).to.be.false;
 
@@ -68,12 +68,12 @@ describe( 'FontSizeCommand', () => {
 
 			expect( command.value ).to.be.true;
 
-			expect( getData( doc ) ).to.equal( '<paragraph>a[<$text fontSize="text-huge">bcfo]obar</$text>xyz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>a[<$text fontSize="text-huge">bcfo]obar</$text>xyz</paragraph>' );
 		} );
 
 		it( 'should add fontSize attribute on selected nodes (multiple nodes)', () => {
 			setData(
-				doc,
+				model,
 				'<paragraph>abcabc[abc</paragraph>' +
 				'<paragraph>foofoofoo</paragraph>' +
 				'<paragraph>barbar]bar</paragraph>'
@@ -83,7 +83,7 @@ describe( 'FontSizeCommand', () => {
 
 			expect( command.value ).to.be.true;
 
-			expect( getData( doc ) ).to.equal(
+			expect( getData( model ) ).to.equal(
 				'<paragraph>abcabc[<$text fontSize="text-huge">abc</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-huge">foofoofoo</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-huge">barbar</$text>]bar</paragraph>'
@@ -92,7 +92,7 @@ describe( 'FontSizeCommand', () => {
 
 		it( 'should change fontSize attribute on selected nodes', () => {
 			setData(
-				doc,
+				model,
 				'<paragraph>abc[abc<$text fontSize="text-small">abc</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-small">foofoofoo</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-small">bar]bar</$text>bar</paragraph>'
@@ -102,7 +102,7 @@ describe( 'FontSizeCommand', () => {
 
 			expect( command.value ).to.be.true;
 
-			expect( getData( doc ) ).to.equal(
+			expect( getData( model ) ).to.equal(
 				'<paragraph>abc[<$text fontSize="text-huge">abcabc</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-huge">foofoofoo</$text></paragraph>' +
 				'<paragraph><$text fontSize="text-huge">bar</$text>]<$text fontSize="text-small">bar</$text>bar</paragraph>'
@@ -110,13 +110,13 @@ describe( 'FontSizeCommand', () => {
 		} );
 
 		it( 'should do nothing on collapsed range', () => {
-			setData( doc, '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
+			setData( model, '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
 
 			expect( command.value ).to.be.true;
 
 			command.execute();
 
-			expect( getData( doc ) ).to.equal( '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
 
 			expect( command.value ).to.be.true;
 		} );

+ 4 - 4
packages/ckeditor5-font/tests/fontsize/fontsizeediting.js

@@ -30,8 +30,8 @@ describe( 'FontSizeEditing', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( doc.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$block' } ) ).to.be.true;
-		expect( doc.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( editor.model.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$block' } ) ).to.be.true;
+		expect( editor.model.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 
 	describe( 'config', () => {
@@ -157,7 +157,7 @@ describe( 'FontSizeEditing', () => {
 				.then( newEditor => {
 					editor = newEditor;
 
-					doc = editor.document;
+					doc = editor.model;
 				} );
 		} );
 
@@ -231,7 +231,7 @@ describe( 'FontSizeEditing', () => {
 				.then( newEditor => {
 					editor = newEditor;
 
-					doc = editor.document;
+					doc = editor.model;
 				} );
 		} );