Browse Source

Changed: ToggleAttributeCommand moved setting selection attributes to enqueueChanges block.

Szymon Cofalik 9 years ago
parent
commit
5bfadcbeda
1 changed files with 10 additions and 10 deletions
  1. 10 10
      packages/ckeditor5-core/src/command/toggleattributecommand.js

+ 10 - 10
packages/ckeditor5-core/src/command/toggleattributecommand.js

@@ -84,15 +84,15 @@ export default class ToggleAttributeCommand extends Command {
 		const selection = document.selection;
 		const value = ( forceValue === undefined ) ? !this.value : forceValue;
 
-		if ( selection.isCollapsed ) {
-			if ( value ) {
-				selection.setAttribute( this.attributeKey, true );
+		// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges.
+		document.enqueueChanges( () => {
+			if ( selection.isCollapsed ) {
+				if ( value ) {
+					selection.setAttribute( this.attributeKey, true );
+				} else {
+					selection.removeAttribute( this.attributeKey );
+				}
 			} else {
-				selection.removeAttribute( this.attributeKey );
-			}
-		} else {
-			// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges.
-			document.enqueueChanges( () => {
 				const ranges = getSchemaValidRanges( this.attributeKey, selection.getRanges(), document.schema );
 
 				// Keep it as one undo step.
@@ -105,7 +105,7 @@ export default class ToggleAttributeCommand extends Command {
 						batch.removeAttribute( range, this.attributeKey );
 					}
 				}
-			} );
-		}
+			}
+		} );
 	}
 }