Merge "Improve truncate and truncateRange to allow negative values"

This commit is contained in:
jenkins-bot 2012-12-11 19:34:07 +00:00 committed by Gerrit Code Review
commit 6460df5cff
2 changed files with 11 additions and 5 deletions

View file

@ -126,7 +126,7 @@ ve.dm.SurfaceFragment.prototype.adjustRange = function ( start, end ) {
* Gets a new fragment with a truncated length.
*
* @method
* @param {Number} limit Maximum length of range
* @param {Number} limit Maximum length of range (negative for left-side truncation)
* @returns {ve.dm.SurfaceFragment} Truncated fragment
*/
ve.dm.SurfaceFragment.prototype.truncateRange = function ( limit ) {

View file

@ -141,14 +141,20 @@ ve.Range.prototype.equals = function ( other ) {
* Creates a new ve.Range object.
*
* @method
* @param {Number} Length of the new range.
* @param {Number} Length of the new range (negative for left-side truncation)
* @returns {ve.Range} A new range.
*/
ve.Range.prototype.truncate = function ( length ) {
this.normalize();
if ( length >= 0 ) {
return new ve.Range(
this.start, Math.max( this.start, Math.min( this.start + length, this.end ) )
this.start, Math.min( this.start + length, this.end )
);
} else {
return new ve.Range(
Math.max( this.end + length, this.start ), this.end
);
}
};
/**