Index: trunk/extensions/VisualEditor/modules/es/bases/es.DocumentBranchNode.js |
— | — | @@ -101,11 +101,17 @@ |
102 | 102 | * @returns {es.DocumentNode|null} Node at offset, or null if non was found |
103 | 103 | */ |
104 | 104 | es.DocumentBranchNode.prototype.getNodeFromOffset = function( offset, shallow ) { |
| 105 | + // TODO a lot of logic is duplicated in selectNodes(), abstract that into a traverser or something |
105 | 106 | if ( this.children.length ) { |
106 | 107 | var nodeOffset = 0, |
107 | 108 | nodeLength, |
108 | 109 | isBranch; |
109 | 110 | 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 | + } |
110 | 116 | nodeLength = this.children[i].getElementLength(); |
111 | 117 | if ( offset >= nodeOffset && offset < nodeOffset + nodeLength ) { |
112 | 118 | isBranch = typeof this.children[i].getChildren === 'function'; |
— | — | @@ -117,6 +123,11 @@ |
118 | 124 | } |
119 | 125 | nodeOffset += nodeLength; |
120 | 126 | } |
| 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 | + } |
121 | 132 | } |
122 | 133 | return null; |
123 | 134 | }; |