Skip to content

Commit

Permalink
Selection change needs to be handled differently.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Aug 10, 2020
1 parent f52c324 commit 1de2e4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
15 changes: 9 additions & 6 deletions packages/ckeditor5-engine/src/view/observer/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] *' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
Expand Down

0 comments on commit 1de2e4e

Please sign in to comment.