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

Change subject: Add cloneWithData() utility
......................................................................


Add cloneWithData() utility

We should probably use this for creating new documents
for references and captions, so we get similar behavior
to cloneFromRange().

Change-Id: I34662b3c8247298531ba34dfbb789293ddebc4d2
---
M src/dm/ve.dm.Document.js
1 file changed, 32 insertions(+), 10 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  Esanders: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js
index 71f5e99..28f0ccb 100644
--- a/src/dm/ve.dm.Document.js
+++ b/src/dm/ve.dm.Document.js
@@ -586,24 +586,46 @@
  * @return {ve.dm.Document} New document
  */
 ve.dm.Document.prototype.cloneFromRange = function ( range ) {
-       var data, newDoc,
-               store = this.getStore().clone(),
-               listRange = 
this.getInternalList().getListNode().getOuterRange();
-
-       data = ve.copy( this.getFullData( range, true ) );
+       var listRange = this.getInternalList().getListNode().getOuterRange(),
+               data = ve.copy( this.getFullData( range, true ) );
        if ( range.start > listRange.start || range.end < listRange.end ) {
                // The range does not include the entire internal list, so add 
it
                data = data.concat( this.getFullData( listRange ) );
        }
+       return this.cloneWithData( data, true );
+};
+
+/**
+ * Create a sub-document associated with this document like #cloneFromRange, 
but without cloning
+ * any data from a range in this document: instead, use the specified data.
+ *
+ * @param {Array} data Linear model data
+ * @param {boolean} [copyInternalList] Copy the internal list
+ * @return {ve.dm.Document} New document
+ */
+ve.dm.Document.prototype.cloneWithData = function ( data, copyInternalList ) {
+       var newDoc,
+               store = this.getStore().clone();
+
        newDoc = new this.constructor(
                new ve.dm.FlatLinearData( store, data ),
-               this.getHtmlDocument(), undefined, this.getInternalList(), 
undefined,
+               // htmlDocument
+               this.getHtmlDocument(),
+               // parentDocument
+               undefined,
+               // internalList
+               copyInternalList ? this.getInternalList() : undefined,
+               // innerWhitespace
+               undefined,
+               // lang+dir
                this.getLang(), this.getDir()
        );
-       // Record the length of the internal list at the time the slice was 
created so we can
-       // reconcile additions properly
-       newDoc.origDoc = this;
-       newDoc.origInternalListLength = this.internalList.getItemNodeCount();
+       if ( copyInternalList ) {
+               // Record the length of the internal list at the time the slice 
was created so we can
+               // reconcile additions properly
+               newDoc.origDoc = this;
+               newDoc.origInternalListLength = 
this.internalList.getItemNodeCount();
+       }
        return newDoc;
 };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I34662b3c8247298531ba34dfbb789293ddebc4d2
Gerrit-PatchSet: 6
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to