|
|
@@ -6,6 +6,7 @@
|
|
|
/* globals window */
|
|
|
|
|
|
import Observer from './observer.js';
|
|
|
+import ViewSelection from '../selection.js';
|
|
|
import { startsWithFiller, getDataWithoutFiller } from '../filler.js';
|
|
|
|
|
|
/**
|
|
|
@@ -191,8 +192,30 @@ export default class MutationObserver extends Observer {
|
|
|
} );
|
|
|
}
|
|
|
|
|
|
- this.document.fire( 'mutations', viewMutations );
|
|
|
+ // Retrieve `domSelection` using `ownerDocument` of one of mutated nodes.
|
|
|
+ // There should not be simultaneous mutation in multiple documents, so it's fine.
|
|
|
+ const domSelection = domMutations[ 0 ].target.ownerDocument.getSelection();
|
|
|
|
|
|
+ let viewSelection = null;
|
|
|
+
|
|
|
+ if ( domSelection && domSelection.anchorNode ) {
|
|
|
+ // If `domSelection` is inside a dom node that is already bound to a view node from view tree, get
|
|
|
+ // corresponding selection in the view and pass it together with `viewMutations`. The `viewSelection` may
|
|
|
+ // be used by features handling mutations.
|
|
|
+ // Only one range is supported.
|
|
|
+
|
|
|
+ const viewSelectionAnchor = domConverter.domPositionToView( domSelection.anchorNode, domSelection.anchorOffset );
|
|
|
+ const viewSelectionFocus = domConverter.domPositionToView( domSelection.focusNode, domSelection.focusOffset );
|
|
|
+
|
|
|
+ // Anchor and focus has to be properly mapped to view.
|
|
|
+ if ( viewSelectionAnchor && viewSelectionFocus ) {
|
|
|
+ viewSelection = new ViewSelection();
|
|
|
+ viewSelection.collapse( viewSelectionAnchor );
|
|
|
+ viewSelection.setFocus( viewSelectionFocus );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.document.fire( 'mutations', viewMutations, viewSelection );
|
|
|
this.document.render();
|
|
|
}
|
|
|
}
|