Ver código fonte

Selection change needs to be handled differently.

Piotrek Koszuliński 5 anos atrás
pai
commit
1de2e4ed3a

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

@@ -75,7 +75,7 @@ export default class DomEventObserver extends Observer {
 
 		types.forEach( type => {
 			this.listenTo( domElement, type, ( eventInfo, domEvent ) => {
-				if ( this.isEnabled && !this.checkShouldIgnoreEvent( domEvent ) ) {
+				if ( this.isEnabled && !this.checkShouldIgnoreEventFromTarget( domEvent.target ) ) {
 					this.onDomEvent( domEvent );
 				}
 			}, { useCapture: this.useCapture } );

+ 9 - 6
packages/ckeditor5-engine/src/view/observer/observer.js

@@ -90,17 +90,20 @@ export default class Observer {
 	 * {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement `DowncastWriter#createUIElement()`} to ignore events
 	 * fired within a UI that should be excluded from CKEditor 5's realms.
 	 *
-	 * @param {Event} domEvent The DOM event to check.
+	 * @param {Node} domTarget The DOM event target to check (usually an element, sometimes a text node and
+	 * potentially sometimes a document too).
 	 * @returns {Boolean} Whether this event should be ignored by the observer.
 	 */
-	checkShouldIgnoreEvent( domEvt ) {
-		// The event's target could be the document itself and possibly other objects (that implement the native EventTarget interface).
-		// The data-cke-ignore-events attribute can only be used on elements, so skip other objects.
-		if ( domEvt.target.nodeType !== 1 ) {
+	checkShouldIgnoreEventFromTarget( domTarget ) {
+		if ( domTarget.nodeType === 3 ) {
+			domTarget = domTarget.parentNode;
+		}
+
+		if ( !domTarget || domTarget.nodeType !== 1 ) {
 			return false;
 		}
 
-		return domEvt.target.matches( '[data-cke-ignore-events], [data-cke-ignore-events] *' );
+		return domTarget.matches( '[data-cke-ignore-events], [data-cke-ignore-events] *' );
 	}
 
 	/**

+ 3 - 2
packages/ckeditor5-engine/src/view/observer/selectionobserver.js

@@ -131,7 +131,9 @@ export default class SelectionObserver extends Observer {
 			return;
 		}
 
-		if ( this.checkShouldIgnoreEvent( domEvent ) ) {
+		const domSelection = domDocument.defaultView.getSelection();
+
+		if ( this.checkShouldIgnoreEventFromTarget( domSelection.anchorNode ) ) {
 			return;
 		}
 
@@ -140,7 +142,6 @@ export default class SelectionObserver extends Observer {
 
 		// If there were mutations then the view will be re-rendered by the mutation observer and selection
 		// will be updated, so selections will equal and event will not be fired, as expected.
-		const domSelection = domDocument.defaultView.getSelection();
 		const newViewSelection = this.domConverter.domSelectionToView( domSelection );
 
 		// Do not convert selection change if the new view selection has no ranges in it.