Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -196,6 +196,62 @@ |
197 | 197 | location.item.flow.content.insert( location.offset, content ); |
198 | 198 | }; |
199 | 199 | |
| 200 | +/** |
| 201 | + * Deletes content in a block within a range. |
| 202 | + * |
| 203 | + * @method |
| 204 | + * @param range {es.Range} Range of content to remove |
| 205 | + */ |
| 206 | +es.ListBlock.prototype.deleteContent = function( range ) { |
| 207 | + range.normalize(); |
| 208 | + |
| 209 | + var locationStart = this.getLocationFromOffset( range.start ), |
| 210 | + locationEnd = this.getLocationFromOffset( range.end ); |
| 211 | + |
| 212 | + if ( locationStart.item == locationEnd.item ) { |
| 213 | + // delete content within one item |
| 214 | + locationStart.item.content.remove( |
| 215 | + new es.Range( locationStart.offset, locationStart.offset + range.getLength() ) |
| 216 | + ); |
| 217 | + } else { |
| 218 | + // delete content across multiple items |
| 219 | + |
| 220 | + // delete selected content from first selected item |
| 221 | + locationStart.item.content.remove( |
| 222 | + new es.Range( |
| 223 | + locationStart.offset, |
| 224 | + locationStart.item.content.getLength() |
| 225 | + ) |
| 226 | + ); |
| 227 | + |
| 228 | + // grab not selected content from last selected item and append it to first selected item |
| 229 | + locationStart.item.content.insert( locationStart.offset, locationEnd.item.content.getContent( |
| 230 | + new es.Range( |
| 231 | + locationEnd.offset, |
| 232 | + locationEnd.item.content.getLength() |
| 233 | + ) |
| 234 | + ).data ); |
| 235 | + |
| 236 | + // delete all selected items except first one |
| 237 | + var deleting = false; |
| 238 | + for ( var i = 0; i < this.list.items.length; i++ ) { |
| 239 | + if ( this.list.items[i] == locationStart.item ) { |
| 240 | + deleting = true; |
| 241 | + continue; |
| 242 | + } else if ( this.list.items[i] == locationEnd.item ) { |
| 243 | + this.list.items[i].list.remove( this.list.items[i] ); |
| 244 | + break; |
| 245 | + } |
| 246 | + if ( deleting ) { |
| 247 | + this.list.items[i].list.remove( this.list.items[i] ); |
| 248 | + i--; |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + this.enumerate(); |
| 253 | + } |
| 254 | +}; |
| 255 | + |
200 | 256 | es.ListBlock.prototype.getText = function( range, render ) { |
201 | 257 | return ""; |
202 | 258 | }; |