All files / src/dm/selections ve.dm.LinearSelection.js

97.22% Statements 35/36
87.5% Branches 7/8
100% Functions 15/15
97.22% Lines 35/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145                        1x   3579x     3579x   3579x         1x       1x             1x 105x               1x 467x                 1x 1x           1x 2x           1x 62x           1x 1x           1x 49x           1x 1378x           1x 1013x           1x 748x           1x 140x           1x 2868x               1x 19667x           1x 3390x                 1x  
/*!
 * VisualEditor Linear Selection class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * @class
 * @extends ve.dm.Selection
 * @constructor
 * @param {ve.Range} range Range
 */
ve.dm.LinearSelection = function VeDmLinearSelection( range ) {
	// Parent constructor
	Iif ( ve.dm.Document && arguments[ 0 ] instanceof ve.dm.Document ) {
		throw new Error( 'Got obsolete ve.dm.Document argument' );
	}
	ve.dm.LinearSelection.super.call( this );
 
	this.range = range;
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.LinearSelection, ve.dm.Selection );
 
/* Static Properties */
 
ve.dm.LinearSelection.static.name = 'linear';
 
/* Static Methods */
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.static.newFromHash = function ( hash ) {
	return new ve.dm.LinearSelection( ve.Range.static.newFromHash( hash.range ) );
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.toJSON = function () {
	return {
		type: this.constructor.static.name,
		range: this.range
	};
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.getDescription = function () {
	return 'Linear: ' + this.range.from + ' - ' + this.range.to;
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.collapseToStart = function () {
	return new this.constructor( new ve.Range( this.getRange().start ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.collapseToEnd = function () {
	return new this.constructor( new ve.Range( this.getRange().end ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.collapseToFrom = function () {
	return new this.constructor( new ve.Range( this.getRange().from ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.collapseToTo = function () {
	return new this.constructor( new ve.Range( this.getRange().to ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.isCollapsed = function () {
	return this.getRange().isCollapsed();
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.translateByTransaction = function ( tx, excludeInsertion ) {
	return new this.constructor( tx.translateRange( this.getRange(), excludeInsertion ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.translateByTransactionWithAuthor = function ( tx, authorId ) {
	return new this.constructor( tx.translateRangeWithAuthor( this.getRange(), authorId ) );
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.getRanges = function () {
	return [ this.range ];
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.getCoveringRange = function () {
	return this.range;
};
 
/**
 * Get the range for this selection
 *
 * @return {ve.Range} Range
 */
ve.dm.LinearSelection.prototype.getRange = function () {
	return this.range;
};
 
/**
 * @inheritdoc
 */
ve.dm.LinearSelection.prototype.equals = function ( other ) {
	return this === other || (
		!!other &&
		other.constructor === this.constructor &&
		this.getRange().equals( other.getRange() )
	);
};
 
/* Registration */
 
ve.dm.selectionFactory.register( ve.dm.LinearSelection );