Parcourir la source

Changed: Use undefined as command value to pass to unset font attribute.

Maciej Gołaszewski il y a 8 ans
Parent
commit
a01ff5547a

+ 1 - 1
packages/ckeditor5-font/src/fontcommand.js

@@ -70,7 +70,7 @@ export default class FontCommand extends Command {
 			const ranges = model.schema.getValidRanges( selection.getRanges(), this.attribute );
 
 			for ( const range of ranges ) {
-				if ( value && value !== 'default' ) {
+				if ( value ) {
 					writer.setAttribute( this.attribute, value, range );
 				} else {
 					writer.removeAttribute( this.attribute, range );

+ 2 - 2
packages/ckeditor5-font/src/fontfamily/fontfamilyediting.js

@@ -47,7 +47,7 @@ export default class FontFamilyEditing extends Plugin {
 		const editing = editor.editing;
 
 		// Add converters from view to model.
-		const items = this.configuredItems.filter( item => item.model !== 'default' );
+		const items = this.configuredItems.filter( item => item.model );
 
 		for ( const item of items ) {
 			viewToModelAttribute( 'fontFamily', item, [ data.viewToModel ] );
@@ -106,7 +106,7 @@ function getItemDefinition( item ) {
 	if ( item === 'default' ) {
 		return {
 			title: 'Default', // TODO localize us
-			model: 'default'
+			model: undefined
 		};
 	}
 

+ 1 - 1
packages/ckeditor5-font/src/fontfamily/fontfamilyui.js

@@ -75,7 +75,7 @@ export default class FontFamilyUI extends Plugin {
 
 			// Execute command when an item from the dropdown is selected.
 			this.listenTo( dropdown, 'execute', evt => {
-				editor.execute( evt.source.commandName, { fontFamily: evt.source.commandParam } );
+				editor.execute( evt.source.commandName, { value: evt.source.commandParam } );
 				editor.editing.view.focus();
 			} );
 

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

@@ -43,7 +43,7 @@ export default class FontSizeEditing extends Plugin {
 		const editing = editor.editing;
 
 		// Define view to model conversion.
-		const items = this.configuredItems.filter( item => item.model !== 'normal' );
+		const items = this.configuredItems.filter( item => item.model );
 
 		for ( const item of items ) {
 			// Covert view to model.
@@ -142,7 +142,7 @@ function getItemDefinition( item ) {
 
 	if ( item === 'normal' ) {
 		return {
-			model: 'normal',
+			model: undefined,
 			title: 'Normal'
 		};
 	}

+ 1 - 1
packages/ckeditor5-font/src/fontsize/fontsizeui.js

@@ -69,7 +69,7 @@ export default class FontSizeUI extends Plugin {
 
 			// Execute command when an item from the dropdown is selected.
 			this.listenTo( dropdown, 'execute', evt => {
-				editor.execute( evt.source.commandName, { fontSize: evt.source.commandParam } );
+				editor.execute( evt.source.commandName, { value: evt.source.commandParam } );
 				editor.editing.view.focus();
 			} );
 

+ 5 - 0
packages/ckeditor5-font/tests/fontfamily/fontfamilyediting.js

@@ -76,6 +76,7 @@ describe( 'FontFamilyEditing', () => {
 					plugins: [ FontFamilyEditing ],
 					fontFamily: {
 						items: [
+							'default',
 							{
 								title: 'Comic Sans',
 								model: 'comic',
@@ -96,6 +97,10 @@ describe( 'FontFamilyEditing', () => {
 
 					expect( plugin.configuredItems ).to.deep.equal( [
 						{
+							model: undefined,
+							title: 'Default'
+						},
+						{
 							title: 'Comic Sans',
 							model: 'comic',
 							view: {

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

@@ -56,7 +56,7 @@ describe( 'FontSizeEditing', () => {
 
 					const plugin = editor.plugins.get( FontSizeEditing );
 
-					expect( plugin.configuredItems ).to.deep.equal( [ { title: 'Normal', model: 'normal' } ] );
+					expect( plugin.configuredItems ).to.deep.equal( [ { title: 'Normal', model: undefined } ] );
 				} );
 		} );
 
@@ -100,7 +100,7 @@ describe( 'FontSizeEditing', () => {
 						expect( plugin.configuredItems ).to.deep.equal( [
 							{ title: 'Tiny', model: 'text-tiny', view: { name: 'span', class: 'text-tiny' } },
 							{ title: 'Small', model: 'text-small', view: { name: 'span', class: 'text-small' } },
-							{ title: 'Normal', model: 'normal' },
+							{ title: 'Normal', model: undefined },
 							{ title: 'Big', model: 'text-big', view: { name: 'span', class: 'text-big' } },
 							{ title: 'Huge', model: 'text-huge', view: { name: 'span', class: 'text-huge' } }
 						] );
@@ -125,7 +125,7 @@ describe( 'FontSizeEditing', () => {
 						expect( plugin.configuredItems ).to.deep.equal( [
 							{ title: '10', model: '10', view: { name: 'span', style: { 'font-size': '10px' } } },
 							{ title: '12', model: '12', view: { name: 'span', style: { 'font-size': '12px' } } },
-							{ title: 'Normal', model: 'normal' },
+							{ title: 'Normal', model: undefined },
 							{ title: '14', model: '14', view: { name: 'span', style: { 'font-size': '14px' } } },
 							{ title: '18', model: '18', view: { name: 'span', style: { 'font-size': '18px' } } }
 						] );