8
0
فهرست منبع

Remove fake selection container before inspecting changed child nodes in Renderer.render().

Maciej Gołaszewski 7 سال پیش
والد
کامیت
78b5a699eb
2فایلهای تغییر یافته به همراه29 افزوده شده و 2 حذف شده
  1. 4 2
      packages/ckeditor5-engine/src/view/renderer.js
  2. 25 0
      packages/ckeditor5-engine/tests/view/renderer.js

+ 4 - 2
packages/ckeditor5-engine/src/view/renderer.js

@@ -171,6 +171,10 @@ export default class Renderer {
 	render() {
 	render() {
 		let inlineFillerPosition;
 		let inlineFillerPosition;
 
 
+		// Remove unneeded fake selection container from the DOM so it will not affect the DOM nodes diffing.
+		// It will be re-added if needed when rendering the selection.
+		this._removeFakeSelection();
+
 		// Refresh mappings.
 		// Refresh mappings.
 		for ( const element of this.markedChildren ) {
 		for ( const element of this.markedChildren ) {
 			this._updateChildrenMappings( element );
 			this._updateChildrenMappings( element );
@@ -660,7 +664,6 @@ export default class Renderer {
 		// If there is no selection - remove DOM and fake selections.
 		// If there is no selection - remove DOM and fake selections.
 		if ( this.selection.rangeCount === 0 ) {
 		if ( this.selection.rangeCount === 0 ) {
 			this._removeDomSelection();
 			this._removeDomSelection();
-			this._removeFakeSelection();
 
 
 			return;
 			return;
 		}
 		}
@@ -676,7 +679,6 @@ export default class Renderer {
 		if ( this.selection.isFake ) {
 		if ( this.selection.isFake ) {
 			this._updateFakeSelection( domRoot );
 			this._updateFakeSelection( domRoot );
 		} else {
 		} else {
-			this._removeFakeSelection();
 			this._updateDomSelection( domRoot );
 			this._updateDomSelection( domRoot );
 		}
 		}
 	}
 	}

+ 25 - 0
packages/ckeditor5-engine/tests/view/renderer.js

@@ -3320,6 +3320,31 @@ describe( 'Renderer', () => {
 				return viewData.repeat( repeat );
 				return viewData.repeat( repeat );
 			}
 			}
 		} );
 		} );
+
+		it( 'should work with fake selection container', () => {
+			let viewString = '';
+
+			for ( let i = 0; i < 151; i++ ) {
+				viewString += '<container:p>foo</container:p>';
+			}
+
+			viewRoot._appendChild( parse( viewString ) );
+
+			// Set fake selection
+			selection._setTo( viewRoot.getChild( 1 ), 'on', { fake: true } );
+
+			renderer.markToSync( 'children', viewRoot );
+			renderer.render();
+
+			viewRoot._removeChildren( 1, 1 );
+			selection._setTo( viewRoot.getChild( 0 ), 'in' );
+
+			renderer.markToSync( 'children', viewRoot );
+
+			expect( () => {
+				renderer.render();
+			} ).to.not.throw();
+		} );
 	} );
 	} );
 
 
 	describe( '#922', () => {
 	describe( '#922', () => {