r101459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101458‎ | r101459 | r101460 >
Date:08:47, 1 November 2011
Author:catrope
Status:deferred
Tags:
Comment:
Followup r101443, that code can't possibly be right. Account for the case where the range is entirely within one child but shallow is set to true.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/bases/es.DocumentNode.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentNode.js
@@ -102,7 +102,7 @@
103103 *
104104 * @method
105105 * @param {es.Range} range Range to select nodes within
106 - * @param {Boolean} [shallow] Do not iterate into child nodes of child nodes
 106+ * @param {Boolean} [shallow] Do not recurse into child nodes of child nodes
107107 * @returns {Array} List of objects with 'node' and 'range' properties describing nodes which are
108108 * covered by the range and the range within the node that is covered
109109 */
@@ -158,11 +158,16 @@
159159 startInside = start >= left && start <= right; // is the start inside this[i]?
160160 endInside = end >= left && end <= right; // is the end inside this[i]?
161161
162 - if ( !shallow && startInside && endInside ) {
 162+ if ( startInside && endInside ) {
163163 // The range is entirely inside this[i]
164 - // Recurse into this[i]
 164+ if ( shallow ) {
 165+ nodes = [ { 'node': this[i], 'range': new es.Range( start - left, end - left ) } ];
 166+ } else {
 167+ // Recurse into this[i]
 168+ nodes = this[i].selectNodes( new es.Range( start - left, end - left ) );
 169+ }
165170 // Since the start and end are both inside this[i], we know for sure that we're done, so return
166 - return this[i].selectNodes( new es.Range( start - left, end - left ) );
 171+ return nodes;
167172 } else if ( startInside ) {
168173 // The start is inside this[i] but the end isn't
169174 // Add a range from the start of the range to the end of this[i]

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101443Added shallow argument to selectNodes methodtparscal00:13, 1 November 2011

Status & tagging log