jenkins-bot has submitted this change and it was merged.
Change subject: Convenience compareDocumentOrder method
......................................................................
Convenience compareDocumentOrder method
Change-Id: I69529a4ad59c6c817581264083a261df510db0fe
---
M src/ce/ve.ce.Surface.js
M src/ve.utils.js
2 files changed, 26 insertions(+), 12 deletions(-)
Approvals:
Jforrester: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 8bb587c..9bad070 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1181,8 +1181,7 @@
* @param {boolean} fixupCursor If destroying unicorns, fix the cursor
position for expected movement
*/
ve.ce.Surface.prototype.checkUnicorns = function ( fixupCursor ) {
- var preUnicorn, postUnicorn, range, node, fixup, ancestor,
- endCursorPos, preUnicornPos;
+ var preUnicorn, postUnicorn, range, node, fixup;
if ( !this.unicorningNode || !this.unicorningNode.unicorns ) {
return;
}
@@ -1210,18 +1209,12 @@
// Selection endpoint is not between unicorns.
// Test whether it is before or after the pre-unicorn (i.e.
before/after both unicorns)
- ancestor = ve.getCommonAncestor( range.endContainer, preUnicorn );
- if ( ancestor === null ) {
- throw new Error( 'No common ancestor' );
- }
- endCursorPos = ve.getOffsetPath( ancestor, range.endContainer,
range.endOffset );
- preUnicornPos = ve.getOffsetPath(
- ancestor,
+ if ( ve.compareDocumentOrder(
+ range.endContainer,
+ range.endOffset,
preUnicorn.parentNode,
Array.prototype.indexOf.call( preUnicorn.parentNode.childNodes,
preUnicorn )
- );
-
- if ( ve.compareOffsetPaths( endCursorPos, preUnicornPos ) < 0 ) {
+ ) < 0 ) {
// before the pre-unicorn
fixup = -1;
} else {
diff --git a/src/ve.utils.js b/src/ve.utils.js
index fc1c7ce..332b659 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1165,6 +1165,27 @@
};
/**
+ * Compare two nodes for position in document
+ *
+ * @param {Node} node1 First node
+ * @param {number} offset1 First offset
+ * @param {Node} node2 Second node
+ * @param {number} offset2 Second offset
+ * @return {number} negative, zero or positive number
+ */
+ve.compareDocumentOrder = function ( node1, offset1, node2, offset2 ) {
+
+ var commonAncestor = ve.getCommonAncestor( node1, node2 );
+ if ( commonAncestor === null ) {
+ throw new Error( 'No common ancestor' );
+ }
+ return ve.compareOffsetPaths(
+ ve.getOffsetPath( commonAncestor, node1, offset1 ),
+ ve.getOffsetPath( commonAncestor, node2, offset2 )
+ );
+};
+
+/**
* Get the client platform string from the browser.
*
* HACK: This is a wrapper for calling getSystemPlatform() on the current
platform
--
To view, visit https://gerrit.wikimedia.org/r/179361
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I69529a4ad59c6c817581264083a261df510db0fe
Gerrit-PatchSet: 4
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits