浏览代码

Default style's command should remove attribute from model.

Szymon Kupś 8 年之前
父节点
当前提交
c138d6a1e5

+ 7 - 1
packages/ckeditor5-image/src/imagestyle/imagestylecommand.js

@@ -79,7 +79,13 @@ export default class ImageStyleCommand extends Command {
 		doc.enqueueChanges( () => {
 			const batch = options.batch || doc.batch();
 
-			batch.setAttribute( imageElement, 'imageStyle', this.style.name );
+			// Default style means that there is no `imageStyle` attribute in the model.
+			// https://github.com/ckeditor/ckeditor5-image/issues/147
+			if ( this.style.isDefault ) {
+				batch.removeAttribute( imageElement, 'imageStyle', this.style.name );
+			} else {
+				batch.setAttribute( imageElement, 'imageStyle', this.style.name );
+			}
 		} );
 	}
 }

+ 17 - 0
packages/ckeditor5-image/tests/imagestyle/imagestylecommand.js

@@ -105,4 +105,21 @@ describe( 'ImageStyleCommand', () => {
 		expect( defaultStyleCommand.isEnabled ).to.be.false;
 		expect( otherStyleCommand.isEnabled ).to.be.false;
 	} );
+
+	it( 'default style should be active after executing it after another style', () => {
+		setData( document, '[<image></image>]' );
+
+		expect( defaultStyleCommand.value ).to.be.true;
+		expect( otherStyleCommand.value ).to.be.false;
+
+		otherStyleCommand.execute();
+
+		expect( getData( document ) ).to.equal( '[<image imageStyle="otherStyle"></image>]' );
+
+		defaultStyleCommand.execute();
+
+		expect( getData( document ) ).to.equal( '[<image></image>]' );
+		expect( defaultStyleCommand.value ).to.be.true;
+		expect( otherStyleCommand.value ).to.be.false;
+	} );
 } );