Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentNode.js |
— | — | @@ -102,27 +102,32 @@ |
103 | 103 | * |
104 | 104 | * @method |
105 | 105 | * @param {es.Range} range Range to select nodes within |
| 106 | + * @param {Boolean} [shallow] Do not iterate into child nodes of child nodes |
106 | 107 | * @returns {Array} List of objects with 'node' and 'range' properties describing nodes which are |
107 | 108 | * covered by the range and the range within the node that is covered |
108 | 109 | */ |
109 | | -es.DocumentNode.prototype.selectNodes = function( range ) { |
110 | | - var nodes = [], i, left, right, start, end, startInside, endInside; |
| 110 | +es.DocumentNode.prototype.selectNodes = function( range, shallow ) { |
111 | 111 | range.normalize(); |
112 | | - start = range.start; |
113 | | - end = range.end; |
| 112 | + var nodes = [], |
| 113 | + i, |
| 114 | + left, |
| 115 | + right, |
| 116 | + start = range.start, |
| 117 | + end = range.end, |
| 118 | + startInside, |
| 119 | + endInside; |
114 | 120 | |
115 | 121 | if ( start < 0 ) { |
116 | 122 | throw 'The start offset of the range is negative'; |
117 | 123 | } |
118 | 124 | |
119 | | - |
120 | | - if ( this.length == 0 ) { |
| 125 | + if ( this.length === 0 ) { |
121 | 126 | // Special case: this node doesn't have any children |
122 | 127 | // The return value is simply the range itself, if it is not out of bounds |
123 | 128 | if ( end > this.getContentLength() ) { |
124 | 129 | throw 'The end offset of the range is past the end of the node'; |
125 | 130 | } |
126 | | - return [ { 'node': this, 'range': new es.Range( start, end ) } ]; |
| 131 | + return [{ 'node': this, 'range': new es.Range( start, end ) }]; |
127 | 132 | } |
128 | 133 | |
129 | 134 | // This node has children, loop over them |
— | — | @@ -153,7 +158,7 @@ |
154 | 159 | startInside = start >= left && start <= right; // is the start inside this[i]? |
155 | 160 | endInside = end >= left && end <= right; // is the end inside this[i]? |
156 | 161 | |
157 | | - if ( startInside && endInside ) { |
| 162 | + if ( !shallow && startInside && endInside ) { |
158 | 163 | // The range is entirely inside this[i] |
159 | 164 | // Recurse into this[i] |
160 | 165 | // Since the start and end are both inside this[i], we know for sure that we're done, so return |
— | — | @@ -182,7 +187,7 @@ |
183 | 188 | |
184 | 189 | // If we got here, that means that at least some part of the range is out of bounds |
185 | 190 | // This is an error |
186 | | - if ( nodes.length == 0 ) { |
| 191 | + if ( nodes.length === 0 ) { |
187 | 192 | throw 'The start offset of the range is past the end of the node'; |
188 | 193 | } else { |
189 | 194 | // Apparently the start was inside this node, but the end wasn't |