8
0
Эх сурвалжийг харах

Changed the way of overriding Command#isEnabled.

Oskar Wróbel 8 жил өмнө
parent
commit
01a12ea502

+ 4 - 3
packages/ckeditor5-core/src/command.js

@@ -79,7 +79,9 @@ export default class Command {
 		// By default commands are disabled when editor switches to read-only mode.
 		this.listenTo( editor, 'change:isReadOnly', ( evt, name, value ) => {
 			if ( value ) {
-				this.on( 'change:isEnabled', forceDisable, { priority: 'high' } );
+				// See ticket about overriding observable properties
+				// https://github.com/ckeditor/ckeditor5-utils/issues/171.
+				this.on( 'change:isEnabled', forceDisable, { priority: 'lowest' } );
 				this.isEnabled = false;
 			} else {
 				this.off( 'change:isEnabled', forceDisable );
@@ -88,9 +90,8 @@ export default class Command {
 		} );
 
 		// Forces command#isEnabled value to be false.
-		function forceDisable( evt ) {
+		function forceDisable() {
 			this.isEnabled = false;
-			evt.stop();
 		}
 	}
 

+ 13 - 0
packages/ckeditor5-core/tests/command.js

@@ -85,6 +85,19 @@ describe( 'Command', () => {
 			// And is back to true.
 			expect( command.isEnabled ).to.true;
 		} );
+
+		it( 'is observable when is overridden', () => {
+			editor.isReadOnly = false;
+			command.isEnabled = true;
+
+			editor.bind( 'something' ).to( command, 'isEnabled' );
+
+			expect( editor.something ).to.true;
+
+			editor.isReadOnly = true;
+
+			expect( editor.something ).to.false;
+		} );
 	} );
 
 	describe( 'execute()', () => {