diff --git a/modules/ve/dm/ve.dm.SurfaceFragment.js b/modules/ve/dm/ve.dm.SurfaceFragment.js index 9a1026f724..44b53c9ee9 100644 --- a/modules/ve/dm/ve.dm.SurfaceFragment.js +++ b/modules/ve/dm/ve.dm.SurfaceFragment.js @@ -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 ) { diff --git a/modules/ve/ve.Range.js b/modules/ve/ve.Range.js index 1b987d0e38..67eb00ac5d 100644 --- a/modules/ve/ve.Range.js +++ b/modules/ve/ve.Range.js @@ -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(); - return new ve.Range( - this.start, Math.max( this.start, Math.min( this.start + length, this.end ) ) - ); + if ( length >= 0 ) { + return new ve.Range( + this.start, Math.min( this.start + length, this.end ) + ); + } else { + return new ve.Range( + Math.max( this.end + length, this.start ), this.end + ); + } }; /**