r102574 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102573‎ | r102574 | r102575 >
Date:21:15, 9 November 2011
Author:catrope
Status:deferred
Tags:
Comment:
Fix selectNodes() behavior for structural offsets (i.e. offsets between two openings/closings). There are no test cases for this yet but I'll write some after Trevor finishes his massive test data change
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/bases/es.DocumentBranchNode.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/bases/es.DocumentBranchNode.js
@@ -101,11 +101,17 @@
102102 * @returns {es.DocumentNode|null} Node at offset, or null if non was found
103103 */
104104 es.DocumentBranchNode.prototype.getNodeFromOffset = function( offset, shallow ) {
 105+ // TODO a lot of logic is duplicated in selectNodes(), abstract that into a traverser or something
105106 if ( this.children.length ) {
106107 var nodeOffset = 0,
107108 nodeLength,
108109 isBranch;
109110 for ( var i = 0, length = this.children.length; i < length; i++ ) {
 111+ if ( offset == nodeOffset ) {
 112+ // The requested offset is right before this.children[i],
 113+ // so it's not inside any of this's children, but inside this
 114+ return this;
 115+ }
110116 nodeLength = this.children[i].getElementLength();
111117 if ( offset >= nodeOffset && offset < nodeOffset + nodeLength ) {
112118 isBranch = typeof this.children[i].getChildren === 'function';
@@ -117,6 +123,11 @@
118124 }
119125 nodeOffset += nodeLength;
120126 }
 127+ if ( offset == nodeOffset ) {
 128+ // The requested offset is right before this.children[i],
 129+ // so it's not inside any of this's children, but inside this
 130+ return this;
 131+ }
121132 }
122133 return null;
123134 };

Status & tagging log