jenkins-bot has submitted this change and it was merged. Change subject: Fix RangeState detection of selection outisde of document ......................................................................
Fix RangeState detection of selection outisde of document Previous logic was mistakenly treating 'selection' as if it was a real native selection, which it isn't. Fix logic to use the correct variable, and detect if you are inside the document node the same way we do in ve.ce.Surface#onFocusChange. Refactor RangeState slightly to pass in the documentNode only. Change-Id: I37903f4f79fa77d1cf1def6b30f90c0592675c74 --- M src/ce/ve.ce.RangeState.js M src/ce/ve.ce.SurfaceObserver.js 2 files changed, 18 insertions(+), 25 deletions(-) Approvals: Divec: 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 1301d1a..6dbd250 100644 --- a/src/ce/ve.ce.RangeState.js +++ b/src/ce/ve.ce.RangeState.js @@ -11,11 +11,10 @@ * * @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 {ve.ce.DocumentNode} documentNode Document node * @param {boolean} selectionOnly The caller promises the content has not changed from old */ -ve.ce.RangeState = function VeCeRangeState( old, $surfaceElement, docNode, selectionOnly ) { +ve.ce.RangeState = function VeCeRangeState( old, documentNode, selectionOnly ) { /** * @property {boolean} branchNodeChanged Whether the CE branch node changed */ @@ -51,7 +50,7 @@ */ this.hash = null; - this.saveState( old, $surfaceElement, docNode, selectionOnly ); + this.saveState( old, documentNode, selectionOnly ); }; /* Inheritance */ @@ -64,35 +63,30 @@ * 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 {ve.ce.DocumentNode} documentNode Document node * @param {boolean} selectionOnly The caller promises the content has not changed from old */ -ve.ce.RangeState.prototype.saveState = function ( old, $surfaceElement, docNode, selectionOnly ) { - var $node, selection, anchorNodeChanged; +ve.ce.RangeState.prototype.saveState = function ( old, documentNode, selectionOnly ) { + var $node, selection, anchorNodeChanged, + nativeSelection = documentNode.getElementDocument().getSelection(); - // Freeze selection out of live object. - selection = ( function ( liveSelection ) { - return { - focusNode: liveSelection.focusNode, - focusOffset: liveSelection.focusOffset, - anchorNode: liveSelection.anchorNode, - anchorOffset: liveSelection.anchorOffset - }; - }( 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] + nativeSelection.rangeCount && !OO.ui.contains( documentNode.$element[0], nativeSelection.anchorNode, true ) ) { + // Use a blank selection if the selection is outside the document selection = { focusNode: null, focusOffset: null, anchorNode: null, anchorOffset: null + }; + } else { + // Freeze selection out of live object. + selection = { + focusNode: nativeSelection.focusNode, + focusOffset: nativeSelection.focusOffset, + anchorNode: nativeSelection.anchorNode, + anchorOffset: nativeSelection.anchorOffset }; } @@ -117,7 +111,7 @@ } else { this.node = $node.data( 'view' ); // Check this node belongs to our document - if ( this.node && this.node.root !== docNode ) { + if ( this.node && this.node.root !== documentNode ) { this.node = null; this.veRange = null; } diff --git a/src/ce/ve.ce.SurfaceObserver.js b/src/ce/ve.ce.SurfaceObserver.js index c0a4a64..222e192 100644 --- a/src/ce/ve.ce.SurfaceObserver.js +++ b/src/ce/ve.ce.SurfaceObserver.js @@ -206,7 +206,6 @@ oldState = this.rangeState; newState = new ve.ce.RangeState( oldState, - this.surface.$element, this.documentView.getDocumentNode(), selectionOnly ); -- To view, visit https://gerrit.wikimedia.org/r/198483 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I37903f4f79fa77d1cf1def6b30f90c0592675c74 Gerrit-PatchSet: 4 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Divec <da...@sheetmusic.org.uk> Gerrit-Reviewer: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits