Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/selections/ve.dm.LinearSelection.js

raw symbols SCIP
1 /*!
2 * VisualEditor Linear Selection class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * @class
9 * @extends ve.dm.Selection
10 * @constructor
11 * @param {ve.Range} range
12 */
13 ve.dm.LinearSelection = function VeDmLinearSelection( range ) {
14 // Parent constructor
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 /* Inheritance */
24
25 OO.inheritClass( ve.dm.LinearSelection, ve.dm.Selection );
26
27 /* Static Properties */
28
29 ve.dm.LinearSelection.static.name = 'linear';
30
31 /* Static Methods */
32
33 /**
34 * @inheritdoc
35 */
36 ve.dm.LinearSelection.static.newFromHash = function ( hash ) {
37 return new ve.dm.LinearSelection( ve.Range.static.newFromHash( hash.range ) );
38 };
39
40 /* Methods */
41
42 /**
43 * @inheritdoc
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 * @inheritdoc
54 */
55 ve.dm.LinearSelection.prototype.getDescription = function () {
56 return 'Linear: ' + this.range.from + ' - ' + this.range.to;
57 };
58
59 /**
60 * @inheritdoc
61 */
62 ve.dm.LinearSelection.prototype.collapseToStart = function () {
63 return new this.constructor( new ve.Range( this.getRange().start ) );
64 };
65
66 /**
67 * @inheritdoc
68 */
69 ve.dm.LinearSelection.prototype.collapseToEnd = function () {
70 return new this.constructor( new ve.Range( this.getRange().end ) );
71 };
72
73 /**
74 * @inheritdoc
75 */
76 ve.dm.LinearSelection.prototype.collapseToFrom = function () {
77 return new this.constructor( new ve.Range( this.getRange().from ) );
78 };
79
80 /**
81 * @inheritdoc
82 */
83 ve.dm.LinearSelection.prototype.collapseToTo = function () {
84 return new this.constructor( new ve.Range( this.getRange().to ) );
85 };
86
87 /**
88 * @inheritdoc
89 */
90 ve.dm.LinearSelection.prototype.isCollapsed = function () {
91 return this.getRange().isCollapsed();
92 };
93
94 /**
95 * @inheritdoc
96 */
97 ve.dm.LinearSelection.prototype.translateByTransaction = function ( tx, excludeInsertion ) {
98 return new this.constructor( tx.translateRange( this.getRange(), excludeInsertion ) );
99 };
100
101 /**
102 * @inheritdoc
103 */
104 ve.dm.LinearSelection.prototype.translateByTransactionWithAuthor = function ( tx, authorId ) {
105 return new this.constructor( tx.translateRangeWithAuthor( this.getRange(), authorId ) );
106 };
107
108 /**
109 * @inheritdoc
110 */
111 ve.dm.LinearSelection.prototype.getRanges = function () {
112 return [ this.range ];
113 };
114
115 /**
116 * @inheritdoc
117 */
118 ve.dm.LinearSelection.prototype.getCoveringRange = function () {
119 return this.range;
120 };
121
122 /**
123 * Get the range for this selection
124 *
125 * @return {ve.Range}
126 */
127 ve.dm.LinearSelection.prototype.getRange = function () {
128 return this.range;
129 };
130
131 /**
132 * @inheritdoc
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 /* Registration */
143
144 ve.dm.selectionFactory.register( ve.dm.LinearSelection );