소스 검색

Made the Editor instance refresh the state of all commands as soon as #dataReady.

Aleksander Nowodzinski 8 년 전
부모
커밋
564bcb6c85
2개의 변경된 파일22개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      packages/ckeditor5-core/src/editor/editor.js
  2. 14 0
      packages/ckeditor5-core/tests/editor/editor.js

+ 8 - 0
packages/ckeditor5-core/src/editor/editor.js

@@ -89,6 +89,14 @@ export default class Editor {
 		 */
 		this.data = new DataController( this.document );
 
+		// Refresh the state of all editor commands as soon as data is ready.
+		// https://github.com/ckeditor/ckeditor5-core/issues/50
+		this.listenTo( this, 'dataReady', () => {
+			for ( const command of this.commands.values() ) {
+				command.refreshState();
+			}
+		} );
+
 		/**
 		 * Instance of the {@link module:engine/controller/editingcontroller~EditingController editing controller}.
 		 *

+ 14 - 0
packages/ckeditor5-core/tests/editor/editor.js

@@ -107,6 +107,20 @@ describe( 'Editor', () => {
 
 			expect( editor.config.get( 'bar' ) ).to.equal( 'foo' );
 		} );
+
+		// https://github.com/ckeditor/ckeditor5-core/issues/50
+		it( 'should attach #dataReady listener to refresh state of the commands', () => {
+			const editor = new Editor();
+			const command = {
+				refreshState: sinon.spy()
+			};
+
+			editor.commands.set( 'foo', command );
+			editor.commands.set( 'bar', command );
+			editor.fire( 'dataReady' );
+
+			sinon.assert.calledTwice( command.refreshState );
+		} );
 	} );
 
 	describe( 'plugins', () => {