| Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js |
| — | — | @@ -113,19 +113,30 @@ |
| 114 | 114 | } |
| 115 | 115 | }; |
| 116 | 116 | |
| | 117 | +/** |
| | 118 | + * Get the parent node that would be affected by inserting given data into it's child. |
| | 119 | + * |
| | 120 | + * This is used when inserting data that closes and reopens one or more parent nodes into a child |
| | 121 | + * node, which requires rebuilding at a higher level. |
| | 122 | + * |
| | 123 | + * @method |
| | 124 | + * @param {es.DocumentNode} node Child node to start from |
| | 125 | + * @param {Array} data Data to inspect for closings |
| | 126 | + * @returns {es.DocumentNode} Lowest level parent node being affected |
| | 127 | + */ |
| 117 | 128 | es.TransactionProcessor.prototype.getScope = function( node, data ) { |
| 118 | 129 | var i, |
| 119 | 130 | length, |
| 120 | 131 | level = 0, |
| 121 | | - maxDepth = 0; |
| | 132 | + max = 0; |
| 122 | 133 | for ( i = 0, length = data.length; i < length; i++ ) { |
| 123 | 134 | if ( typeof data[i].type === 'string' ) { |
| 124 | | - level += data[i].type.charAt( 0 ) === '/' ? -1 : 1; |
| 125 | | - maxDepth = Math.max( maxDepth, -level ); |
| | 135 | + level += data[i].type.charAt( 0 ) === '/' ? 1 : -1; |
| | 136 | + max = Math.max( max, level ); |
| 126 | 137 | } |
| 127 | 138 | } |
| 128 | | - if ( maxDepth > 0 ) { |
| 129 | | - for ( i = 0; i < maxDepth - 1; i++ ) { |
| | 139 | + if ( max > 0 ) { |
| | 140 | + for ( i = 0; i < max - 1; i++ ) { |
| 130 | 141 | node = node.getParent(); |
| 131 | 142 | } |
| 132 | 143 | } |