Divec has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/192077

Change subject: Fix unmodifiedness test in showSelection
......................................................................

Fix unmodifiedness test in showSelection

The test was using ve.compare on native ranges, which fails to detect any 
differences
on firefox because nativeRange.hasOwnProperty returns false for the four 
relevant
properties (startContainer/startOffset/endContainer/endOffset). Replace with a 
test of
each of those properties (which is more explicit and efficient in any case).

Bug: T90306
Change-Id: If4d00ed80934bcab7907ed7cc6b3ff5264c711f3
---
M src/ce/ve.ce.Surface.js
1 file changed, 17 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/77/192077/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 3190ea8..161cd8f 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -3410,7 +3410,7 @@
                return;
        }
 
-       var endRange,
+       var endRange, oldRange,
                range = selection.getRange(),
                rangeSelection = this.getRangeSelection( range ),
                nativeRange = this.getElementDocument().createRange();
@@ -3431,12 +3431,24 @@
                        // see 
https://bugzilla.mozilla.org/show_bug.cgi?id=921444
                        this.nativeSelection.addRange( nativeRange );
                }
+       } else if ( !(
+               this.nativeSelection.rangeCount > 0 &&
+               ( oldRange = this.nativeSelection.getRangeAt( 0 ) ) &&
+               oldRange.startContainer === nativeRange.startContainer &&
+               oldRange.startOffset === nativeRange.startOffset &&
+               oldRange.endContainer === nativeRange.endContainer &&
+               oldRange.endOffset === nativeRange.endOffset
+       ) ) {
+               // Genuine selection change: apply it.
+               // TODO: this is slightly too zealous, because a cursor 
position at a node edge
+               // can have more than one (container,offset) representation
+               this.nativeSelection.removeAllRanges();
+               this.nativeSelection.addRange( nativeRange );
        } else {
-               if ( !this.nativeSelection.rangeCount || !ve.compare( 
nativeRange, this.nativeSelection.getRangeAt( 0 ) ) ) {
-                       this.nativeSelection.removeAllRanges();
-                       this.nativeSelection.addRange( nativeRange );
-               }
+               // Not a selection change: don't needlessly reapply the same 
selection.
+               return;
        }
+
        // Setting a range doesn't give focus in all browsers so make sure this 
happens
        // Also set focus after range to prevent scrolling to top
        if ( !OO.ui.contains( this.getElementDocument().activeElement, 
rangeSelection.start.node, true ) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4d00ed80934bcab7907ed7cc6b3ff5264c711f3
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <da...@sheetmusic.org.uk>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to