8
0
Pārlūkot izejas kodu

Ignore mutations with bogus BRs one the end of the block element.

Krzysztof Krztoń 8 gadi atpakaļ
vecāks
revīzija
d8fca0e709

+ 23 - 1
packages/ckeditor5-engine/src/view/observer/mutationobserver.js

@@ -149,7 +149,7 @@ export default class MutationObserver extends Observer {
 			if ( mutation.type === 'childList' ) {
 				const element = domConverter.getCorrespondingViewElement( mutation.target );
 
-				if ( element ) {
+				if ( element && !this._isBogusBrMutation( mutation ) ) {
 					mutatedElements.add( element );
 				}
 			}
@@ -233,6 +233,28 @@ export default class MutationObserver extends Observer {
 		// view (which has not been changed). In order to "reset DOM" we render the view again.
 		this.document.render();
 	}
+
+	/**
+	 * Checks if mutation was generated by the browser inserting bogus br on the end of the block element.
+	 * Such mutations are generated while pressing space or performing native spellchecker correction
+	 * on the end of the block element in Firefox browser.
+	 *
+	 * @private
+	 * @param {Object} mutation Native mutation object.
+	 * @returns {Boolean}
+	 */
+	_isBogusBrMutation( mutation ) {
+		let addedNode = null;
+
+		// Check if mutation added only one node on the end of its parent.
+		if ( mutation.nextSibling === null && mutation.removedNodes.length === 0 && mutation.addedNodes.length == 1 ) {
+			addedNode = this.domConverter.domToView( mutation.addedNodes[ 0 ], {
+				withChildren: false
+			} );
+		}
+
+		return addedNode && addedNode.is( 'element', 'br' );
+	}
 }
 
 /**