8
0
Просмотр исходного кода

Fixed: DomConverter#viewPositionToDom should return null if view position is after a view element that has not been rendered to DOM.

Szymon Cofalik 9 лет назад
Родитель
Сommit
479e293708

+ 6 - 0
packages/ckeditor5-engine/src/view/domconverter.js

@@ -278,6 +278,12 @@ export default class DomConverter {
 				domAfter = domParent.childNodes[ 0 ];
 			} else {
 				domBefore = this.getCorrespondingDom( viewPosition.nodeBefore );
+
+				if ( !domBefore ) {
+					// Position is after a view element that has not been rendered to DOM yet.
+					return null;
+				}
+
 				domParent = domBefore.parentNode;
 				domAfter = domBefore.nextSibling;
 			}

+ 12 - 0
packages/ckeditor5-engine/tests/view/domconverter/view-to-dom.js

@@ -508,6 +508,18 @@ describe( 'DomConverter', () => {
 			expect( domPosition.offset ).to.equal( INLINE_FILLER_LENGTH );
 			expect( domPosition.parent ).to.equal( domFiller );
 		} );
+
+		it( 'should return null if view position is after a view element that has not been rendered to DOM', () => {
+			const domP = createElement( document, 'p', null );
+			const { view: viewP, selection } = parse( '<container:p><attribute:b>foo</attribute:b>[]</container:p>' );
+
+			converter.bindElements( domP, viewP );
+
+			const viewPosition = selection.getFirstPosition();
+			const domPosition = converter.viewPositionToDom( viewPosition );
+
+			expect( domPosition ).to.equal( null );
+		} );
 	} );
 
 	describe( 'viewRangeToDom', () => {