浏览代码

Tests: MutationObserver provided a test for a case when DOM selection is in a new node.

Szymon Cofalik 9 年之前
父节点
当前提交
b8a8e981fe

+ 2 - 0
packages/ckeditor5-engine/src/view/observer/mutationobserver.js

@@ -238,6 +238,8 @@ export default class MutationObserver extends Observer {
  * Array of mutations.
  * For mutated texts it will be {@link engine.view.Document~MutatatedText} and for mutated elements it will be
  * {@link engine.view.Document~MutatatedElement}. You can recognize the type based on the `type` property.
+ * @param {engine.view.Selection|null} View selection that is a result of converting DOM selection to view. Keep in
+ * mind that the DOM selection is already "updated", meaning that it already acknowledges changes done in mutation.
  */
 
 /**

+ 17 - 0
packages/ckeditor5-engine/tests/view/observer/mutationobserver.js

@@ -132,6 +132,23 @@ describe( 'MutationObserver', () => {
 		expectDomEditorNotToChange();
 	} );
 
+	it( 'should fire mutations event with viewSelection param set to null, if dom selection cannot be mapped to view', ( done ) => {
+		const textNode = domEditor.ownerDocument.createTextNode( 'foo' );
+		domEditor.childNodes[ 0 ].appendChild( textNode );
+
+		const domSelection = document.getSelection();
+		domSelection.collapse( textNode, 3 );
+
+		viewDocument.on( 'mutations', ( evt, viewMutations, viewSelection ) => {
+			expect( viewSelection ).to.be.null;
+			done();
+		} );
+
+		mutationObserver.flush();
+
+		expectDomEditorNotToChange();
+	} );
+
 	it( 'should be able to observe multiple roots', () => {
 		const domAdditionalEditor = document.getElementById( 'additional' );