Ver Fonte

Fixed a case when selection was placed in an empty root.

Piotrek Koszuliński há 9 anos atrás
pai
commit
fe3c8ebc38

+ 10 - 0
packages/ckeditor5-engine/tests/_utils-tests/model.js

@@ -87,6 +87,16 @@ describe( 'model test utils', () => {
 				] );
 			} );
 
+			it( 'writes selection in an empty root', () => {
+				const root = document.createRoot( 'empty', '$root' );
+
+				selection.collapse( root );
+
+				expect( getData( document, 'empty', options ) ).to.equal(
+					'<selection />'
+				);
+			} );
+
 			it( 'writes selection collapsed in an element', () => {
 				selection.collapse( root );
 

+ 3 - 2
packages/ckeditor5-engine/tests/_utils/model.js

@@ -21,11 +21,12 @@ import Element from '/ckeditor5/engine/treemodel/element.js';
  * @returns {String} The stringified data.
  */
 export function getData( document, rootName, options ) {
+	const root = document.getRoot( rootName );
 	const walker = new TreeWalker( {
-		boundaries: Range.createFromElement( document.getRoot( rootName ) )
+		boundaries: Range.createFromElement( root )
 	} );
 	let ret = '';
-	let lastPosition;
+	let lastPosition = Position.createFromParentAndOffset( root, 0 );
 	const selection = document.selection;
 
 	options = options || {};