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
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                          3561×     3561×   3561×                           105×               462×                                     61×                     52×           1373×           1004×           747×           140×           2862×               17003×           3388×                  
/*!
 * VisualEditor Linear Selection class.
 *
 * @copyright 2011-2019 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 );