Sfoglia il codice sorgente

Tests: Added test for disabling rendering of a fresh view by the controller until first changes were made to the model.

Aleksander Nowodzinski 7 anni fa
parent
commit
9bfe76cda5

+ 5 - 0
packages/ckeditor5-engine/src/controller/editingcontroller.js

@@ -69,6 +69,11 @@ export default class EditingController {
 		const selection = doc.selection;
 		const markers = this.model.markers;
 
+		// When taking over an editing view, disable the rendering until the first
+		// changes were made to the model. This allows a free manipulation of the view root
+		// attributes without any risk of breaking anything, for instance, the initial content
+		// of the DOM root element. If the rendering was allowed, any change of attributes would
+		// trigger rendering and synchronize the DOM root with a (still) empty model.
 		this.view._renderingDisabled = true;
 
 		// When plugins listen on model changes (on selection change, post fixers, etc) and change the view as a result of

+ 27 - 0
packages/ckeditor5-engine/tests/controller/editingcontroller.js

@@ -348,6 +348,33 @@ describe( 'EditingController', () => {
 				.to.equal( '<p></p><p>f<span>oo</span></p><p>bar</p>' );
 		} );
 
+		it( 'should prevent rendering of a fresh view until the first changes mere made to the model', () => {
+			const model = new Model();
+			model.document.createRoot();
+
+			const editing = new EditingController( model );
+			const domRoot = document.createElement( 'div' );
+			domRoot.contentEditable = true;
+
+			document.body.appendChild( domRoot );
+
+			const viewRoot = editing.view.document.getRoot();
+			editing.view.attachDomRoot( domRoot );
+
+			editing.view.change( writer => {
+				writer.setAttribute( 'new-attribute', 'foo', viewRoot );
+			} );
+
+			expect( domRoot.hasAttribute( 'new-attribute' ) ).to.be.false;
+
+			model.change( () => {} );
+
+			expect( domRoot.getAttribute( 'new-attribute' ) ).to.equal( 'foo' );
+
+			document.body.removeChild( domRoot );
+			editing.destroy();
+		} );
+
 		describe( 'preventing rendering while in the model.change() block', () => {
 			let renderSpy;