浏览代码

Internal: Used `beforeChange` instead of `change` to force command read-only mode.

Oskar Wróbel 7 年之前
父节点
当前提交
d4f9530675
共有 1 个文件被更改,包括 8 次插入8 次删除
  1. 8 8
      packages/ckeditor5-core/src/command.js

+ 8 - 8
packages/ckeditor5-core/src/command.js

@@ -79,19 +79,13 @@ export default class Command {
 		// By default commands are disabled when the editor is in read-only mode.
 		this.listenTo( editor, 'change:isReadOnly', ( evt, name, value ) => {
 			if ( value ) {
-				// See a ticket about overriding observable properties
-				// https://github.com/ckeditor/ckeditor5-utils/issues/171.
-				this.on( 'change:isEnabled', forceDisable, { priority: 'lowest' } );
+				this.on( 'beforeChange:isEnabled', forceDisable, { priority: 'highest' } );
 				this.isEnabled = false;
 			} else {
-				this.off( 'change:isEnabled', forceDisable );
+				this.off( 'beforeChange:isEnabled', forceDisable );
 				this.refresh();
 			}
 		} );
-
-		function forceDisable() {
-			this.isEnabled = false;
-		}
 	}
 
 	/**
@@ -139,3 +133,9 @@ export default class Command {
 }
 
 mix( Command, ObservableMixin );
+
+// Helper function that forces command to be disabled.
+function forceDisable( evt ) {
+	evt.return = false;
+	evt.stop();
+}