浏览代码

Fixed: `jumpOverUiElement` fix should not throw if dom position cannot be converted to view.

Szymon Cofalik 8 年之前
父节点
当前提交
722bf420d2

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

@@ -112,6 +112,12 @@ function jumpOverUiElement( evt, data, domConverter ) {
 			const domOffset = domSelection.getRangeAt( 0 ).startOffset;
 
 			const viewPosition = domConverter.domPositionToView( domParent, domOffset );
+
+			// In case if dom element is not converted to view or is not mapped or something. Happens for example in some tests.
+			if ( viewPosition === null ) {
+				return;
+			}
+
 			// Skip all following ui elements.
 			const nextViewPosition = viewPosition.getLastMatchingPosition( value => value.item.is( 'uiElement' ) );
 

+ 10 - 0
packages/ckeditor5-engine/tests/view/document/jumpoveruielement.js

@@ -87,5 +87,15 @@ describe( 'Document', () => {
 			expect( domSelection.anchorOffset ).to.equal( 2 );
 			expect( domSelection.isCollapsed ).to.be.true;
 		} );
+
+		it( 'should do nothing if dom position cannot be converted to view position', () => {
+			const newDiv = document.createElement( 'div' );
+			const domSelection = document.getSelection();
+
+			document.body.appendChild( newDiv );
+			domSelection.collapse( newDiv, 0 );
+
+			viewDocument.fire( 'keydown', { keyCode: keyCodes.arrowright, domTarget: viewDocument.domRoots.get( 'main' ) } );
+		} );
 	} );
 } );