Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/76106
Change subject: Rename index to offset in AnnotationSet
......................................................................
Rename index to offset in AnnotationSet
To avoid confusion between IV store indexes and the index
within the set, rename the latter to offset.
Change-Id: Ic7d741bd5d39240d63fdc04a2df45658a64441de
---
M modules/ve/dm/ve.dm.AnnotationSet.js
M modules/ve/test/dm/ve.dm.AnnotationSet.test.js
2 files changed, 39 insertions(+), 39 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/06/76106/1
diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js
b/modules/ve/dm/ve.dm.AnnotationSet.js
index 5b2dc30..244f663 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -10,7 +10,7 @@
*
* @constructor
* @param {ve.dm.IndexValueStore} store Index-value store
- * @param {number[]} [indexes] Array of indexes into the store
+ * @param {number[]} [indexes] Array of store indexes
*/
ve.dm.AnnotationSet = function VeDmAnnotationSet( store, indexes ) {
// Parent constructor
@@ -82,17 +82,17 @@
/**
* Get an annotation or all annotations from the set.
*
- * set.get( 5 ) returns the annotation at index 5, set.get() returns an array
with all annotations
+ * set.get( 5 ) returns the annotation at offset 5, set.get() returns an array
with all annotations
* in the entire set.
*
* @method
- * @param {number} [index] If set, only get the annotation at the index
- * @returns {ve.dm.Annotation[]|ve.dm.Annotation|undefined} The annotation at
index, or an array of all
+ * @param {number} [offset] If set, only get the annotation at the offset
+ * @returns {ve.dm.Annotation[]|ve.dm.Annotation|undefined} The annotation at
offset, or an array of all
* annotations in the set
*/
-ve.dm.AnnotationSet.prototype.get = function ( index ) {
- if ( index !== undefined ) {
- return this.getStore().value( this.getIndex( index ) );
+ve.dm.AnnotationSet.prototype.get = function ( offset ) {
+ if ( offset !== undefined ) {
+ return this.getStore().value( this.getIndex( offset ) );
} else {
return this.getStore().values( this.getIndexes() );
}
@@ -145,18 +145,18 @@
* @returns {boolean} There is an annotation in the set with the same hash as
annotation
*/
ve.dm.AnnotationSet.prototype.contains = function ( annotation ) {
- return this.indexOf( annotation ) !== -1;
+ return this.offsetOf( annotation ) !== -1;
};
/**
* Check whether a given store index occurs in the set.
*
* @method
- * @param {number} annotation Index of annotation in the store
+ * @param {number} index Store index of annotation
* @returns {boolean} There is an annotation in the set with this store index
*/
ve.dm.AnnotationSet.prototype.containsIndex = function ( index ) {
- return ve.indexOf( index , this.getIndexes() ) !== -1;
+ return ve.indexOf( index, this.getIndexes() ) !== -1;
};
/**
@@ -194,13 +194,13 @@
};
/**
- * Get the index of a given annotation in the set.
+ * Get the offset of a given annotation in the set.
*
* @method
* @param {ve.dm.Annotation} annotation Annotation to search for
- * @returns {number} Index of annotation in the set, or -1 if annotation is
not in the set.
+ * @returns {number} Offset of annotation in the set, or -1 if annotation is
not in the set.
*/
-ve.dm.AnnotationSet.prototype.indexOf = function ( annotation ) {
+ve.dm.AnnotationSet.prototype.offsetOf = function ( annotation ) {
return ve.indexOf( this.store.indexOfHash( ve.getHash( annotation ) ),
this.getIndexes() );
};
@@ -316,28 +316,28 @@
*
* If the annotation is already present in the set, nothing happens.
*
- * The annotation will be inserted before the annotation that is currently at
the given index. If index is
- * negative, it will be counted from the end (i.e. index -1 is the last item,
-2 the second-to-last,
- * etc.). If index is out of bounds, the annotation will be added to the end
of the set.
+ * The annotation will be inserted before the annotation that is currently at
the given offset. If offset is
+ * negative, it will be counted from the end (i.e. offset -1 is the last item,
-2 the second-to-last,
+ * etc.). If offset is out of bounds, the annotation will be added to the end
of the set.
*
* @method
* @param {ve.dm.Annotation} annotation Annotation to add
- * @param {number} index Index to add the annotation at
+ * @param {number} offset Offset to add the annotation at
*/
-ve.dm.AnnotationSet.prototype.add = function ( annotation, index ) {
+ve.dm.AnnotationSet.prototype.add = function ( annotation, offset ) {
var storeIndex = this.getStore().index( annotation );
// negative offset
- if ( index < 0 ) {
- index = this.getLength() + index;
+ if ( offset < 0 ) {
+ offset = this.getLength() + offset;
}
// greater than length, add to end
- if ( index >= this.getLength() ) {
+ if ( offset >= this.getLength() ) {
this.push( annotation );
return;
}
// if not in set already, splice in place
if ( !this.containsIndex( storeIndex ) ) {
- this.storeIndexes.splice( index, 0, storeIndex );
+ this.storeIndexes.splice( offset, 0, storeIndex );
}
};
@@ -365,20 +365,20 @@
};
/**
- * Remove the annotation at a given index.
+ * Remove the annotation at a given offset.
*
* @method
- * @param {number} index Index to remove item at. If negative, the counts from
the end, see add()
- * @throws {Error} Index out of bounds.
+ * @param {number} offset Offset to remove item at. If negative, the counts
from the end, see add()
+ * @throws {Error} Offset out of bounds.
*/
-ve.dm.AnnotationSet.prototype.removeAt = function ( index ) {
- if ( index < 0 ) {
- index = this.getLength() + index;
+ve.dm.AnnotationSet.prototype.removeAt = function ( offset ) {
+ if ( offset < 0 ) {
+ offset = this.getLength() + offset;
}
- if ( index >= this.getLength() ) {
- throw new Error( 'Index out of bounds' );
+ if ( offset >= this.getLength() ) {
+ throw new Error( 'Offset out of bounds' );
}
- this.storeIndexes.splice( index, 1 );
+ this.storeIndexes.splice( offset, 1 );
};
/**
@@ -390,9 +390,9 @@
* @param {ve.dm.Annotation} annotation Annotation to remove
*/
ve.dm.AnnotationSet.prototype.remove = function ( annotation ) {
- var index = this.indexOf( annotation );
- if ( index !== -1 ) {
- this.storeIndexes.splice( index, 1 );
+ var offset = this.offsetOf( annotation );
+ if ( offset !== -1 ) {
+ this.storeIndexes.splice( offset, 1 );
}
};
diff --git a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
index 4f49719..3874ac4 100644
--- a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
+++ b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
@@ -30,8 +30,8 @@
assert.equal( annotationSet.containsAnyOf( emptySet ), false,
'containsAnyOf empty set is false' );
assert.equal( annotationSet.containsAllOf( annotationSet2 ), false,
'containsAllOf set2 set is false' );
assert.equal( annotationSet.containsAllOf( annotationSet ), true,
'containsAllOf self is true' );
- assert.equal( annotationSet.indexOf( italic ), 1, 'indexOf italic is 1'
);
- assert.equal( annotationSet.indexOf( underline ), -1, 'indexOf
underline is -1' );
+ assert.equal( annotationSet.offsetOf( italic ), 1, 'offsetOf italic is
1' );
+ assert.equal( annotationSet.offsetOf( underline ), -1, 'offsetOf
underline is -1' );
assert.deepEqual(
annotationSet.filter( function ( annotation ) { return
annotation.name === 'textStyle/bold'; } ).get(),
[ bold ], 'filter for name=textStyle/bold returns just bold
annotation'
@@ -40,11 +40,11 @@
assert.equal( annotationSet.hasAnnotationWithName(
'textStyle/underline' ), false, 'hasAnnotationWithName underline is false' );
annotationSet2.add( bold, 1 );
- assert.equal( annotationSet2.indexOf( bold ), 1, 'set2 contains bold at
1 after add at 1' );
+ assert.equal( annotationSet2.offsetOf( bold ), 1, 'set2 contains bold
at 1 after add at 1' );
annotationSet2.remove( bold );
assert.equal( annotationSet2.contains( bold ), false, 'set2 doesn\'t
contain bold after remove' );
annotationSet2.add( bold, 0 );
- assert.equal( annotationSet2.indexOf( bold ), 0, 'set2 contains bold at
0 after add at 0' );
+ assert.equal( annotationSet2.offsetOf( bold ), 0, 'set2 contains bold
at 0 after add at 0' );
annotationSet2.add( bold, 0 );
assert.equal( annotationSet2.getLength(), 3, 'adding existing
annotation doesn\'t change length' );
// set is now [ bold, italic, underline ]
@@ -65,7 +65,7 @@
assert.equal( annotationSet.contains( italic ) &&
!annotationSet.contains( underline ), true, 'contains italic not underline
after removeNotInSet' );
annotationSet2.add( underline, 1 );
annotationSet3 = annotationSet2.reversed();
- assert.equal( annotationSet3.indexOf( underline ), 0, 'underline has
indexOf 0 after reverse' );
+ assert.equal( annotationSet3.offsetOf( underline ), 0, 'underline has
offsetOf 0 after reverse' );
annotationSet3 = annotationSet.mergeWith( annotationSet2 );
assert.equal( annotationSet3.getLength(), 3, 'set merged with set2 has
length 3' );
annotationSet3 = annotationSet.diffWith( annotationSet2 );
--
To view, visit https://gerrit.wikimedia.org/r/76106
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7d741bd5d39240d63fdc04a2df45658a64441de
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits