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