jenkins-bot has submitted this change and it was merged.

Change subject: Check the selection is in the correct surface
......................................................................


Check the selection is in the correct surface

Previously, if the selection was in another surface, RangeState would silently
use a DM offset computed from the wrong document.

Change-Id: I87cff916690aca2094788bce7f97c95b594818eb
---
M src/ce/ve.ce.RangeState.js
M src/ce/ve.ce.SurfaceObserver.js
2 files changed, 21 insertions(+), 3 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/ce/ve.ce.RangeState.js b/src/ce/ve.ce.RangeState.js
index a719214..ab17c67 100644
--- a/src/ce/ve.ce.RangeState.js
+++ b/src/ce/ve.ce.RangeState.js
@@ -11,10 +11,11 @@
  *
  * @constructor
  * @param {ve.ce.RangeState|null} old Previous range state
+ * @param {jQuery} $surfaceElement The CE Surface $element
  * @param {ve.ce.DocumentNode} docNode The current document node
  * @param {boolean} selectionOnly The caller promises the content has not 
changed from old
  */
-ve.ce.RangeState = function VeCeRangeState( old, docNode, selectionOnly ) {
+ve.ce.RangeState = function VeCeRangeState( old, $surfaceElement, docNode, 
selectionOnly ) {
        /**
         * @property {boolean} branchNodeChanged Whether the CE branch node 
changed
         */
@@ -65,7 +66,7 @@
         */
        this.hash = null;
 
-       this.saveState( old, docNode, selectionOnly );
+       this.saveState( old, $surfaceElement, docNode, selectionOnly );
 };
 
 /* Inheritance */
@@ -78,10 +79,11 @@
  * Saves a snapshot of the current range state
  * @method
  * @param {ve.ce.RangeState|null} old Previous range state
+ * @param {jQuery} $surfaceElement The CE Surface $element
  * @param {ve.ce.DocumentNode} docNode The current document node
  * @param {boolean} selectionOnly The caller promises the content has not 
changed from old
  */
-ve.ce.RangeState.prototype.saveState = function ( old, docNode, selectionOnly 
) {
+ve.ce.RangeState.prototype.saveState = function ( old, $surfaceElement, 
docNode, selectionOnly ) {
        var $nodeOrSlug, selection, anchorNodeChanged;
 
        // Freeze selection out of live object.
@@ -94,6 +96,21 @@
                };
        } ( docNode.getElementDocument().getSelection() ) );
 
+       // Use a blank selection if the selection is outside this surface
+       // (or if the selection is inside another surface inside this one)
+       if (
+               selection.rangeCount && $(
+                       selection.getRangeAt( 0 ).commonAncestorContainer
+               ).closest( '.ve-ce-surface' )[0] !== $surfaceElement[0]
+       ) {
+               selection = {
+                       focusNode: null,
+                       focusOffset: null,
+                       anchorNode: null,
+                       anchorOffset: null
+               };
+       }
+
        // Get new range information
        if ( old && !old.compareSelection( selection ) ) {
                // No change; use old values for speed
diff --git a/src/ce/ve.ce.SurfaceObserver.js b/src/ce/ve.ce.SurfaceObserver.js
index 185c82c..18b8f81 100644
--- a/src/ce/ve.ce.SurfaceObserver.js
+++ b/src/ce/ve.ce.SurfaceObserver.js
@@ -211,6 +211,7 @@
        oldState = this.rangeState;
        newState = new ve.ce.RangeState(
                oldState,
+               this.surface.$element,
                this.documentView.getDocumentNode(),
                selectionOnly
        );

-- 
To view, visit https://gerrit.wikimedia.org/r/177280
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I87cff916690aca2094788bce7f97c95b594818eb
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to