Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -74,11 +74,35 @@ |
75 | 75 | */ |
76 | 76 | es.ListBlock.prototype.annotateContent = function( method, annotation, range ) { |
77 | 77 | range.normalize(); |
78 | | - // TODO: Support annotating multiple items at once |
79 | | - var location = this.list.getLocationFromOffset( range.start ); |
80 | | - location.item.content.annotate( |
81 | | - method, annotation, new es.Range( location.offset, location.offset + range.getLength() ) |
82 | | - ); |
| 78 | + |
| 79 | + var locationStart = this.list.getLocationFromOffset( range.start ), |
| 80 | + locationEnd = this.list.getLocationFromOffset( range.end ); |
| 81 | + |
| 82 | + if ( locationStart.item == locationEnd.item ) { |
| 83 | + |
| 84 | + locationStart.item.content.annotate( method, annotation, locationStart.offset, locationStart.offset + range.end - range.start ); |
| 85 | + |
| 86 | + } else { |
| 87 | + var itemsToAnnotate; |
| 88 | + this.traverseItems( function( item, index ) { |
| 89 | + if ( item == locationEnd.item ) { |
| 90 | + return false; |
| 91 | + } |
| 92 | + if ( $.isArray( itemsToAnnotate ) ) { |
| 93 | + itemsToAnnotate.push( item ); |
| 94 | + } |
| 95 | + if ( item == locationStart.item ) { |
| 96 | + itemsToAnnotate = []; |
| 97 | + } |
| 98 | + } ); |
| 99 | + |
| 100 | + locationStart.item.content.annotate( method, annotation, locationStart.offset, locationStart.item.content.getLength() ); |
| 101 | + locationEnd.item.content.annotate( method, annotation, 0, locationEnd.offset); |
| 102 | + |
| 103 | + for ( var i = 0; i < itemsToAnnotate.length; i++ ) { |
| 104 | + itemsToAnnotate[i].content.annotate( method, annotation, 0, itemsToAnnotate[i].content.getLength()); |
| 105 | + } |
| 106 | + } |
83 | 107 | }; |
84 | 108 | |
85 | 109 | /** |