Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js |
— | — | @@ -101,6 +101,10 @@ |
102 | 102 | // Remove the node we are about to insert into from the model tree |
103 | 103 | parent.splice( index, oldNodes.length ); |
104 | 104 | } |
| 105 | + this.buildNodes( newData, parent, index ); |
| 106 | +}; |
| 107 | + |
| 108 | +es.TransactionProcessor.prototype.buildNodes = function( newData, parent, index ) { |
105 | 109 | // Regenerate nodes for the data we've affected |
106 | 110 | var newNodes = es.DocumentModel.createNodesFromData( newData ); |
107 | 111 | // Insert new elements into the tree where the old ones used to be |
— | — | @@ -177,7 +181,12 @@ |
178 | 182 | |
179 | 183 | es.TransactionProcessor.prototype.insert = function( op ) { |
180 | 184 | if ( es.DocumentModel.isStructuralOffset( this.model.data, this.cursor ) ) { |
181 | | - // TODO: Support tree updates when inserting between elements |
| 185 | + es.insertIntoArray( this.model.data, this.cursor, op.data ); |
| 186 | + this.applyAnnotations( this.cursor + op.data.length ); |
| 187 | + var parent = this.model.getNodeFromOffset( this.cursor ), |
| 188 | + index = parent.getIndexFromOffset( this.cursor ); |
| 189 | + console.log( parent, index ); |
| 190 | + this.buildNodes( op.data, parent, index ); |
182 | 191 | } else { |
183 | 192 | // Get the node we are about to insert into at the lowest depth possible |
184 | 193 | var node = this.getScope( this.model.getNodeFromOffset( this.cursor ), op.data ); |
Index: trunk/extensions/VisualEditor/modules/es/bases/es.DocumentBranchNode.js |
— | — | @@ -257,6 +257,26 @@ |
258 | 258 | }; |
259 | 259 | |
260 | 260 | /** |
| 261 | + * Gets the index of a child node from a given offset. |
| 262 | + * |
| 263 | + * @method |
| 264 | + * @param {Integer} offset Offset to find index of |
| 265 | + * @returns {Integer} Index of child node at offset or -1 if offset was out of range |
| 266 | + */ |
| 267 | +es.DocumentBranchNode.prototype.getIndexFromOffset = function( offset ) { |
| 268 | + var left = 0, |
| 269 | + elementLength; |
| 270 | + for ( var i = 0; i < this.children.length; i++ ) { |
| 271 | + elementLength = this.children[i].getElementLength(); |
| 272 | + if ( offset >= left && offset < left + elementLength ) { |
| 273 | + return i; |
| 274 | + } |
| 275 | + left += elementLength; |
| 276 | + } |
| 277 | + return -1; |
| 278 | +}; |
| 279 | + |
| 280 | +/** |
261 | 281 | * Gets a list of nodes and their sub-ranges which are covered by a given range. |
262 | 282 | * |
263 | 283 | * @method |