mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 14:33:59 +00:00
Add ve.Range.coveringRange()
Change-Id: Ifd9932d7a9f9dae2354fa7aa75cee2e3e639ef42
This commit is contained in:
parent
6f4b68274d
commit
5e4f0293f2
|
@ -28,6 +28,31 @@ ve.Range.newFromTranslatedRange = function( range, distance ) {
|
|||
return new ve.Range( range.from + distance, range.to + distance );
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new ve.Range object that covers all of the given ranges
|
||||
*
|
||||
* @method
|
||||
* @param {Array} ranges Array of ve.Range objects (at least one)
|
||||
* @returns {ve.Range} Range that spans all of the given ranges
|
||||
*/
|
||||
ve.Range.newCoveringRange = function( ranges ) {
|
||||
var minStart, maxEnd, i;
|
||||
if ( !ranges || ranges.length == 0 ) {
|
||||
throw 'newCoveringRange() requires at least one range';
|
||||
}
|
||||
minStart = ranges[0].start;
|
||||
maxEnd = ranges[0].end;
|
||||
for ( i = 1; i < ranges.length; i++ ) {
|
||||
if ( ranges[i].start < minStart ) {
|
||||
minStart = ranges[i].start;
|
||||
}
|
||||
if ( ranges[i].end > maxEnd ) {
|
||||
maxEnd = ranges[i].end;
|
||||
}
|
||||
}
|
||||
return new ve.Range( minStart, maxEnd );
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue