mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
Merge "Improve truncate and truncateRange to allow negative values"
This commit is contained in:
commit
6460df5cff
|
@ -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 ) {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue