浏览代码

Changed: Renderer should re-render also next text node if a text node has changed.

Szymon Cofalik 8 年之前
父节点
当前提交
83ab9d5df7
共有 2 个文件被更改,包括 30 次插入8 次删除
  1. 14 3
      packages/ckeditor5-engine/src/view/renderer.js
  2. 16 5
      packages/ckeditor5-engine/tests/view/renderer.js

+ 14 - 3
packages/ckeditor5-engine/src/view/renderer.js

@@ -10,6 +10,7 @@
 import ViewText from './text';
 import ViewPosition from './position';
 import { INLINE_FILLER, INLINE_FILLER_LENGTH, startsWithFiller, isInlineFiller, isBlockFiller } from './filler';
+import { getTouchingTextNode } from './utils';
 
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import diff from '@ckeditor/ckeditor5-utils/src/diff';
@@ -198,9 +199,7 @@ export default class Renderer {
 		}
 
 		for ( const node of this.markedTexts ) {
-			if ( !this.markedChildren.has( node.parent ) && this.domConverter.mapViewToDom( node.parent ) ) {
-				this._updateText( node, { inlineFillerPosition } );
-			}
+			this._updateText( node, { inlineFillerPosition } );
 		}
 
 		for ( const element of this.markedAttributes ) {
@@ -407,6 +406,12 @@ export default class Renderer {
 	 */
 	_updateText( viewText, options ) {
 		const domText = this.domConverter.findCorrespondingDomText( viewText );
+
+		// If this is a new text node and it is not in DOM, it will be created and handled in `_updateChildren`.
+		if ( !domText ) {
+			return;
+		}
+
 		const newDomText = this.domConverter.viewToDom( viewText, domText.ownerDocument );
 
 		const actualText = domText.data;
@@ -420,6 +425,12 @@ export default class Renderer {
 
 		if ( actualText != expectedText ) {
 			domText.data = expectedText;
+
+			const nextTouchingTextNode = getTouchingTextNode( viewText, true );
+
+			if ( nextTouchingTextNode ) {
+				this.markedTexts.add( nextTouchingTextNode );
+			}
 		}
 	}
 

+ 16 - 5
packages/ckeditor5-engine/tests/view/renderer.js

@@ -214,18 +214,29 @@ describe( 'Renderer', () => {
 			expect( renderer.markedTexts.size ).to.equal( 0 );
 		} );
 
-		it( 'should not update text parent child list changed', () => {
-			const viewImg = new ViewElement( 'img' );
+		it( 'should update next touching text nodes of updated text node', () => {
 			const viewText = new ViewText( 'foo' );
-			viewRoot.appendChildren( [ viewImg, viewText ] );
+
+			viewRoot.appendChildren( [
+				viewText,
+				new ViewAttributeElement( 'strong', null, new ViewText( ' bar' ) )
+			] );
 
 			renderer.markToSync( 'children', viewRoot );
+			renderer.render();
+
+			expect( domRoot.childNodes.length ).to.equal( 2 );
+			expect( domRoot.childNodes[ 0 ].data ).to.equal( 'foo' );
+			expect( domRoot.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( ' bar' );
+
+			viewText.data = 'foo ';
+
 			renderer.markToSync( 'text', viewText );
 			renderer.render();
 
 			expect( domRoot.childNodes.length ).to.equal( 2 );
-			expect( domRoot.childNodes[ 0 ].tagName ).to.equal( 'IMG' );
-			expect( domRoot.childNodes[ 1 ].data ).to.equal( 'foo' );
+			expect( domRoot.childNodes[ 0 ].data ).to.equal( 'foo ' );
+			expect( domRoot.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( '\u00A0bar' );
 		} );
 
 		it( 'should not change text if it is the same during text rendering', () => {