Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -201,11 +201,13 @@ |
202 | 202 | new es.ParagraphModel( data[25], 1 ) |
203 | 203 | ]; |
204 | 204 | |
205 | | -test( 'es.DocumentModel', 8, function() { |
| 205 | +test( 'es.DocumentModel', 11, function() { |
206 | 206 | var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
207 | 207 | |
208 | 208 | deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' ); |
| 209 | + |
209 | 210 | deepEqual( documentModel.slice( 0 ), tree, 'Nodes contain correct lengths' ); |
| 211 | + |
210 | 212 | deepEqual( |
211 | 213 | documentModel[0].getContent( new es.Range( 1, 3 ) ), |
212 | 214 | [ |
— | — | @@ -214,6 +216,7 @@ |
215 | 217 | ], |
216 | 218 | 'When getting content for a node, ranges can trim left' |
217 | 219 | ); |
| 220 | + |
218 | 221 | deepEqual( |
219 | 222 | documentModel[0].getContent( new es.Range( 0, 2 ) ), |
220 | 223 | [ |
— | — | @@ -222,6 +225,7 @@ |
223 | 226 | ], |
224 | 227 | 'When getting content for a node, ranges can trim right' |
225 | 228 | ); |
| 229 | + |
226 | 230 | deepEqual( |
227 | 231 | documentModel[0].getContent( new es.Range( 1, 2 ) ), |
228 | 232 | [ |
— | — | @@ -229,6 +233,7 @@ |
230 | 234 | ], |
231 | 235 | 'When getting content for a node, ranges can trim left and right' |
232 | 236 | ); |
| 237 | + |
233 | 238 | try { |
234 | 239 | documentModel[0].getContent( new es.Range( -1, 3 ) ); |
235 | 240 | } catch ( err ) { |
— | — | @@ -237,6 +242,7 @@ |
238 | 243 | 'Exceptions are thrown when getting node content within a range starting before 0' |
239 | 244 | ); |
240 | 245 | } |
| 246 | + |
241 | 247 | try { |
242 | 248 | documentModel[0].getContent( new es.Range( 0, 4 ) ); |
243 | 249 | } catch ( err ) { |
— | — | @@ -245,5 +251,17 @@ |
246 | 252 | 'Exceptions are thrown when getting node content within a range ending after length' |
247 | 253 | ); |
248 | 254 | } |
| 255 | + |
249 | 256 | deepEqual( documentModel[2].getContent(), ['a'], 'Content can be extracted from nodes' ); |
| 257 | + |
| 258 | + var bold = { 'type': 'bold', 'hash': '#bold' }, |
| 259 | + italic = { 'type': 'italic', 'hash': '#italic' }, |
| 260 | + nothing = { 'type': 'nothing', 'hash': '#nothing' }, |
| 261 | + character = ['a', bold, italic]; |
| 262 | + |
| 263 | + equal( es.DocumentModel.getIndexOfAnnotation( character, bold ), 1 ); |
| 264 | + |
| 265 | + equal( es.DocumentModel.getIndexOfAnnotation( character, italic ), 2 ); |
| 266 | + |
| 267 | + equal( es.DocumentModel.getIndexOfAnnotation( character, nothing ), -1 ); |
250 | 268 | } ); |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -264,10 +264,9 @@ |
265 | 265 | es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) { |
266 | 266 | if ( $.isArray( character ) ) { |
267 | 267 | // Find the index of a comparable annotation (checking for same value, not reference) |
268 | | - var index; |
269 | | - for ( var i = 0; i < character.length; i++ ) { |
270 | | - if ( character[i].hash === op.annotation.hash ) { |
271 | | - return index; |
| 268 | + for ( var i = 1; i < character.length; i++ ) { |
| 269 | + if ( character[i].hash === annotation.hash ) { |
| 270 | + return i; |
272 | 271 | } |
273 | 272 | } |
274 | 273 | } |