mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
Merge "When cloning the InternalList, pass through properties that aren't rebuilt"
This commit is contained in:
commit
c98624a7be
|
@ -416,7 +416,12 @@ ve.dm.InternalList.prototype.sortGroupIndexes = function ( group ) {
|
|||
* @returns {ve.dm.InternalList} Clone of this internal
|
||||
*/
|
||||
ve.dm.InternalList.prototype.clone = function ( doc ) {
|
||||
return new this.constructor( doc || this.getDocument() );
|
||||
var clone = new this.constructor( doc || this.getDocument() );
|
||||
// Most properties don't need to be copied, because addNode() will be invoked when the new
|
||||
// document tree is built. But some do need copying:
|
||||
clone.nextUniqueNumber = this.nextUniqueNumber;
|
||||
clone.itemHtmlQueue = ve.copy( this.itemHtmlQueue );
|
||||
return clone;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,13 +76,22 @@ QUnit.test( 'convertToData', 2, function ( assert ) {
|
|||
assert.deepEqual( internalList.getItemHtmlQueue(), [], 'Items html is emptied after conversion' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'clone', 2, function ( assert ) {
|
||||
var doc = ve.dm.example.createExampleDocument(),
|
||||
QUnit.test( 'clone', 5, function ( assert ) {
|
||||
var internalListClone, internalListClone2,
|
||||
doc = ve.dm.example.createExampleDocument(),
|
||||
doc2 = ve.dm.example.createExampleDocument(),
|
||||
internalList = doc.getInternalList(),
|
||||
internalListClone = internalList.clone(),
|
||||
internalListClone2 = internalList.clone( doc2 );
|
||||
internalList = doc.getInternalList();
|
||||
|
||||
internalList.getNextUniqueNumber(); // =0
|
||||
internalListClone = internalList.clone();
|
||||
internalList.getNextUniqueNumber(); // =1
|
||||
internalListClone2 = internalList.clone( doc2 );
|
||||
internalList.getNextUniqueNumber(); // =2
|
||||
|
||||
assert.equal( internalListClone.getDocument(), internalList.getDocument(), 'Documents match' );
|
||||
assert.equal( internalListClone2.getDocument(), doc2, 'Cloning with document parameter' );
|
||||
|
||||
assert.equal( internalList.getNextUniqueNumber(), 3, 'original internallist has nextUniqueNumber=3' );
|
||||
assert.equal( internalListClone.getNextUniqueNumber(), 1, 'first clone has nextUniqueNumber=1' );
|
||||
assert.equal( internalListClone2.getNextUniqueNumber(), 2, 'second clone has nextUniqueNumber=2' );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue