Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | $document.bind( { |
34 | 34 | 'keydown.ce-surfaceView': function( e ) { |
35 | 35 | // return _this.onKeyDown( e ); |
36 | | - }, |
| 36 | + } |
37 | 37 | } ); |
38 | 38 | }, |
39 | 39 | 'blur': function( e ) { |
— | — | @@ -76,7 +76,6 @@ |
77 | 77 | |
78 | 78 | ve.es.Surface.prototype.onCompositionStart = function( e ) { |
79 | 79 | this.stopPolling(); |
80 | | - |
81 | 80 | var rangySel = rangy.getSelection(); |
82 | 81 | this.poll.compositionStart = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false ); |
83 | 82 | }; |
— | — | @@ -84,7 +83,6 @@ |
85 | 84 | ve.es.Surface.prototype.onCompositionEnd = function( e ) { |
86 | 85 | var rangySel = rangy.getSelection(); |
87 | 86 | this.poll.compositionEnd = this.getOffset( rangySel.focusNode, rangySel.focusOffset, false ); |
88 | | - |
89 | 87 | this.startPolling(); |
90 | 88 | }; |
91 | 89 | |
— | — | @@ -122,11 +120,13 @@ |
123 | 121 | }; |
124 | 122 | |
125 | 123 | ve.es.Surface.prototype.pollContent = function() { |
| 124 | + var localOffset, text, hash; |
| 125 | + |
126 | 126 | if ( this.poll.compositionStart !== null && this.poll.compositionEnd !== null ) { |
127 | 127 | |
128 | | - var text = ve.es.Surface.getDOMText2( this.poll.node ), |
129 | | - hash = ve.es.Surface.getDOMHash( this.poll.node ), |
130 | | - localOffset = this.poll.compositionEnd; |
| 128 | + text = ve.es.Surface.getDOMText2( this.poll.node ); |
| 129 | + hash = ve.es.Surface.getDOMHash( this.poll.node ); |
| 130 | + localOffset = this.poll.compositionEnd; |
131 | 131 | this.poll.compositionStart = null; |
132 | 132 | this.poll.compositionEnd = null; |
133 | 133 | |
— | — | @@ -137,14 +137,14 @@ |
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | | - var node = this.getLeafNode( rangySel.anchorNode )[0], |
142 | | - text = ve.es.Surface.getDOMText2( node ), |
143 | | - hash = ve.es.Surface.getDOMHash( node ); |
| 141 | + var node = this.getLeafNode( rangySel.anchorNode )[0]; |
| 142 | + text = ve.es.Surface.getDOMText2( node ); |
| 143 | + hash = ve.es.Surface.getDOMHash( node ); |
144 | 144 | |
145 | 145 | if ( rangySel.anchorNode !== rangySel.focusNode || rangySel.anchorOffset !== rangySel.focusOffset ) { |
146 | | - var localOffset = null; |
| 146 | + localOffset = null; |
147 | 147 | } else { |
148 | | - var localOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false ); |
| 148 | + localOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, false ); |
149 | 149 | } |
150 | 150 | |
151 | 151 | if ( node !== this.poll.node ) { |
— | — | @@ -155,6 +155,8 @@ |
156 | 156 | return; |
157 | 157 | } |
158 | 158 | } |
| 159 | + |
| 160 | + var newData, annotations; |
159 | 161 | |
160 | 162 | if ( text !== this.poll.prevText ) { |
161 | 163 | var nodeOffset = this.documentView.getOffsetFromNode( $( this.poll.node ).data( 'view' ) ), |
— | — | @@ -162,8 +164,8 @@ |
163 | 165 | offsetDiff = ( localOffset !== null && this.poll.prevOffset !== null ) ? localOffset - this.poll.prevOffset : null; |
164 | 166 | |
165 | 167 | if ( lengthDiff === offsetDiff && this.poll.prevText.substring( 0, this.poll.prevOffset ) === text.substring( 0, this.poll.prevOffset ) ) { |
166 | | - var newData = text.substring( this.poll.prevOffset, localOffset ).split( '' ); |
167 | | - var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 ); |
| 168 | + newData = text.substring( this.poll.prevOffset, localOffset ).split( '' ); |
| 169 | + annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 ); |
168 | 170 | ve.dm.DocumentNode.addAnnotationsToData( newData, annotations ); |
169 | 171 | this.model.transact( this.documentView.model.prepareInsertion( |
170 | 172 | nodeOffset + 1 + this.poll.prevOffset, |
— | — | @@ -173,19 +175,19 @@ |
174 | 176 | var sameFromLeft = 0, |
175 | 177 | sameFromRight = 0, |
176 | 178 | l = text.length > this.poll.prevText.length ? this.poll.prevText.length : text.length; |
177 | | - while ( sameFromLeft < l && this.poll.prevText[sameFromLeft] == text[sameFromLeft] ) { |
| 179 | + while ( sameFromLeft < l && this.poll.prevText[sameFromLeft] === text[sameFromLeft] ) { |
178 | 180 | ++sameFromLeft; |
179 | 181 | } |
180 | 182 | l = l - sameFromLeft; |
181 | | - while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] == text[text.length - 1 - sameFromRight] ) { |
| 183 | + while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] === text[text.length - 1 - sameFromRight] ) { |
182 | 184 | ++sameFromRight; |
183 | 185 | } |
184 | 186 | this.model.transact( this.documentView.model.prepareRemoval( new ve.Range( |
185 | 187 | nodeOffset + 1 + sameFromLeft, |
186 | 188 | nodeOffset + 1 + this.poll.prevText.length - sameFromRight |
187 | 189 | ) ) ); |
188 | | - var newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' ); |
189 | | - var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft ); |
| 190 | + newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' ); |
| 191 | + annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft ); |
190 | 192 | ve.dm.DocumentNode.addAnnotationsToData( newData, annotations ); |
191 | 193 | this.model.transact( this.documentView.model.prepareInsertion( |
192 | 194 | nodeOffset + 1 + sameFromLeft, |
— | — | @@ -250,22 +252,21 @@ |
251 | 253 | }; |
252 | 254 | |
253 | 255 | ve.es.Surface.prototype.showCursorAt = function( offset ) { |
254 | | - var $node = this.documentView.getNodeFromOffset( offset ).$; |
255 | | - var current = [$node.contents(), 0]; |
256 | | - var stack = [current]; |
257 | | - var node; |
258 | | - var localOffset; |
259 | | - |
260 | | - var index = 1 + this.documentView.getOffsetFromNode( $node.data('view') ); |
261 | | - |
| 256 | + var $node = this.documentView.getNodeFromOffset( offset ).$, |
| 257 | + current = [$node.contents(), 0], |
| 258 | + stack = [current], |
| 259 | + node, |
| 260 | + localOffset, |
| 261 | + index = this.documentView.getOffsetFromNode( $node.data('view') ) + 1; |
| 262 | + |
262 | 263 | while ( stack.length > 0 ) { |
263 | 264 | if ( current[1] >= current[0].length ) { |
264 | 265 | stack.pop(); |
265 | 266 | current = stack[ stack.length - 1 ]; |
266 | 267 | continue; |
267 | 268 | } |
268 | | - var item = current[0][current[1]]; |
269 | | - var $item = current[0].eq( current[1] ); |
| 269 | + var item = current[0][current[1]], |
| 270 | + $item = current[0].eq( current[1] ); |
270 | 271 | |
271 | 272 | if ( item.nodeType === 3 ) { |
272 | 273 | var length = item.textContent.length; |
— | — | @@ -290,11 +291,10 @@ |
291 | 292 | } |
292 | 293 | var range = document.createRange(); |
293 | 294 | range.collapsed = true; |
294 | | - range.setStart(node, localOffset); |
295 | | - |
| 295 | + range.setStart( node, localOffset ); |
296 | 296 | var sel = window.getSelection(); |
297 | 297 | sel.removeAllRanges(); |
298 | | - sel.addRange(range); |
| 298 | + sel.addRange( range ); |
299 | 299 | }; |
300 | 300 | |
301 | 301 | ve.es.Surface.prototype.getSelection = function() { |
— | — | @@ -351,15 +351,16 @@ |
352 | 352 | |
353 | 353 | ve.es.Surface.getDOMHash = function( elem ) { |
354 | 354 | var nodeType = elem.nodeType, |
355 | | - nodeName = elem.nodeName, |
| 355 | + nodeName = elem.nodeName, |
356 | 356 | ret = ''; |
357 | 357 | |
358 | 358 | if ( nodeType === 3 || nodeType === 4 ) { |
359 | 359 | return '#'; |
360 | 360 | } else if ( nodeType === 1 || nodeType === 9 ) { |
361 | 361 | ret += '<' + nodeName + '>'; |
| 362 | + // Traverse it's children |
362 | 363 | for ( elem = elem.firstChild; elem; elem = elem.nextSibling) { |
363 | | - ret += ve.es.Surface.getDOMHash( elem ); |
| 364 | + ret += ve.es.Surface.getDOMHash( elem ); |
364 | 365 | } |
365 | 366 | ret += '</' + nodeName + '>'; |
366 | 367 | } |
— | — | @@ -368,4 +369,4 @@ |
369 | 370 | |
370 | 371 | /* Inheritance */ |
371 | 372 | |
372 | | -ve.extendClass( ve.es.Surface, ve.EventEmitter ); |
| 373 | +ve.extendClass( ve.es.Surface, ve.EventEmitter ); |
\ No newline at end of file |