mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 05:56:11 +00:00
ff7b8a2591
ve.dm.Transaction * Replace operations are now built directly from the linear model and automatically determine what metadata replace information they need to include: ** retainMetadata ** replaceMetadata ** insertMetadata ve.dm.Document * Metadata array created empty and padded out after data parsing as we are no longer using Document.spliceData to build it (a new test checks for correct metadata length) * spliceData replaced with getMetadataReplace, which instead returns transactional steps of spliceData (retain, replace, insert) ve.dm.MetaLinearData * Add function for merging metadata items together. Only used once in the code (Document.getMetadataReplace) but useful for generating test data. ve.dm.MetaList * Replace operations with metadata need to calculate new offset and indices directly, but can't be applied immediately lest they put a metaItem out of place and affect findItem. ve.dm.MetaItem * Add methods to support queued moves as required by MetaList Test files * Updated to match new pushReplace API * Remove any instances of Document.spliceData * Extra check on sparse metadata array length * Rewrite spliceData tests as getMetadataReplace tests * Count expected cases in Transaction(Processor) tests Bug: 46954 Change-Id: I4edad1c2dd37c723bff2792bab7d694ef17a86dc
96 lines
2.5 KiB
JavaScript
96 lines
2.5 KiB
JavaScript
/*!
|
|
* VisualEditor MetaLinearData class.
|
|
*
|
|
* Class containing meta linear data and an index-value store.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Meta linear data storage
|
|
*
|
|
* @class
|
|
* @extends ve.dm.LinearData
|
|
* @constructor
|
|
* @param {ve.dm.IndexValueStore} store Index-value store
|
|
* @param {Array} [data] Linear data
|
|
*/
|
|
ve.dm.MetaLinearData = function VeDmMetaLinearData( store, data ) {
|
|
ve.dm.LinearData.call( this, store, data );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.MetaLinearData, ve.dm.LinearData );
|
|
|
|
/* Static Methods */
|
|
|
|
/**
|
|
* Takes an array of meta linear data arrays and collapses them into a single array.
|
|
*
|
|
* Undefined values will be discarded e.g.
|
|
* [ [ metaItem1, metaItem2 ], undefined, [ metaItem3 ], undefined ]
|
|
* =>
|
|
* [ [ metaItem1, metaItem2, metaItem3 ] ]
|
|
*
|
|
* @static
|
|
* @param {Array} data Meta linear data arrays
|
|
* @returns {Array} Merged data
|
|
*/
|
|
ve.dm.MetaLinearData.static.merge = function ( data ) {
|
|
var i, merged = [];
|
|
for ( i = 0; i < data.length; i++ ) {
|
|
if ( data[i] !== undefined ) {
|
|
merged = merged.concat( data[i] );
|
|
}
|
|
}
|
|
return [ merged ];
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Gets linear data from specified index(es).
|
|
*
|
|
* If either index is omitted the array at that point is returned
|
|
*
|
|
* @method
|
|
* @param {number} [offset] Offset to get data from
|
|
* @param {number} [metadataOffset] Index to get data from
|
|
* @returns {Object|Array} Data from index(es), or all data (by reference)
|
|
*/
|
|
ve.dm.MetaLinearData.prototype.getData = function ( offset, metadataOffset ) {
|
|
if ( offset === undefined ) {
|
|
return this.data;
|
|
} else if ( metadataOffset === undefined ) {
|
|
return this.data[offset];
|
|
} else {
|
|
return this.data[offset] === undefined ? undefined : this.data[offset][metadataOffset];
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Gets number of metadata elements at specified offset.
|
|
*
|
|
* @method
|
|
* @param {number} offset Offset to count metadata at
|
|
* @returns {number} Number of metadata elements at specified offset
|
|
*/
|
|
ve.dm.MetaLinearData.prototype.getDataLength = function ( offset ) {
|
|
return this.data[offset] === undefined ? 0 : this.data[offset].length;
|
|
};
|
|
|
|
/**
|
|
* Gets number of metadata elements in the entire object.
|
|
*
|
|
* @method
|
|
* @returns {number} Number of metadata elements in the entire object
|
|
*/
|
|
ve.dm.MetaLinearData.prototype.getTotalDataLength = function () {
|
|
var n = 0, i = this.getLength();
|
|
while ( i-- ) {
|
|
n += this.getDataLength( i );
|
|
}
|
|
return n;
|
|
}; |