Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -40,7 +40,8 @@ |
41 | 41 | this.cursor = { |
42 | 42 | $: $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ ), |
43 | 43 | interval: null, |
44 | | - offset: null |
| 44 | + offset: null, |
| 45 | + initialLeft: null |
45 | 46 | }; |
46 | 47 | |
47 | 48 | // References for use in closures |
— | — | @@ -181,6 +182,7 @@ |
182 | 183 | if ( !this.$input.is( ':focus' ) ) { |
183 | 184 | this.$input.focus().select(); |
184 | 185 | } |
| 186 | + this.cursor.initialLeft = null; |
185 | 187 | return false; |
186 | 188 | }; |
187 | 189 | |
— | — | @@ -272,49 +274,35 @@ |
273 | 275 | }; |
274 | 276 | |
275 | 277 | es.SurfaceView.prototype.moveCursor = function( direction ) { |
276 | | - switch ( direction ) { |
277 | | - case 'left': |
278 | | - this.showCursor( this.cursor.offset - 1 ); |
279 | | - break; |
280 | | - case 'right': |
281 | | - this.showCursor( this.cursor.offset + 1 ); |
282 | | - break; |
283 | | - case 'up': |
284 | | - var currentOffset = this.cursor.offset; |
285 | | - var currentPosition = this.documentView.getRenderedPosition( currentOffset ); |
286 | | - var newPosition = new es.Position(currentPosition.left, currentPosition.top, currentPosition.bottom); |
287 | | - var off = -1; |
288 | | - var newPosTop = newPosition.top; |
| 278 | + if ( direction === 'left' ) { |
| 279 | + this.showCursor( this.cursor.offset - 1 ); |
| 280 | + this.cursor.initialLeft = null; |
| 281 | + } else if ( direction === 'right' ) { |
| 282 | + this.showCursor( this.cursor.offset + 1 ); |
| 283 | + this.cursor.initialLeft = null; |
| 284 | + } else if ( direction === 'up' || direction === 'down' ) { |
| 285 | + var currentPosition = this.documentView.getRenderedPosition( this.cursor.offset ); |
| 286 | + if ( this.cursor.initialLeft === null ) { |
| 287 | + this.cursor.initialLeft = currentPosition.left; |
| 288 | + } |
| 289 | + var fakePosition = new es.Position( this.cursor.initialLeft, currentPosition.top ), |
| 290 | + edgeCondition = ( direction == 'up' ) ? 0 : this.documentView.getLength(), |
| 291 | + offset, |
| 292 | + i = 1; |
289 | 293 | |
290 | | - while ( currentPosition.top === newPosition.top && off !== 0 ) { |
291 | | - newPosTop = newPosTop - 10; |
292 | | - newPosition.top = newPosTop; |
293 | | - off = this.documentView.getOffsetFromPosition( newPosition ); |
294 | | - newPosition = this.documentView.getRenderedPosition( off ); |
| 294 | + do { |
| 295 | + if ( direction == 'up' ) { |
| 296 | + fakePosition.top -= i++ * 10; |
| 297 | + } else { |
| 298 | + fakePosition.top += i++ * 10; |
295 | 299 | } |
296 | | - newPosition.left = currentPosition.left; |
297 | | - this.showCursor( this.documentView.getOffsetFromPosition( newPosition ) ); |
298 | | - break; |
299 | | - case 'down': |
300 | | - var currentOffset = this.cursor.offset; |
301 | | - var currentPosition = this.documentView.getRenderedPosition( currentOffset ); |
302 | | - var newPosition = new es.Position(currentPosition.left, currentPosition.top, currentPosition.bottom); |
303 | | - var off = -1; |
304 | | - var newPosTop = newPosition.top; |
305 | | - var alllength = this.documentView.getLength(); |
306 | | - |
307 | | - while ( currentPosition.top === newPosition.top && off !== alllength ) { |
308 | | - newPosTop = newPosTop + 10; |
309 | | - newPosition.top = newPosTop; |
310 | | - off = this.documentView.getOffsetFromPosition( newPosition ); |
311 | | - newPosition = this.documentView.getRenderedPosition( off ); |
312 | | - } |
313 | | - newPosition.left = currentPosition.left; |
314 | | - this.showCursor( this.documentView.getOffsetFromPosition( newPosition ) ); |
315 | | - break; |
316 | | - default: |
317 | | - break; |
| 300 | + offset = this.documentView.getOffsetFromPosition( fakePosition ); |
| 301 | + fakePosition = this.documentView.getRenderedPosition( offset ); |
| 302 | + fakePosition.left = this.cursor.initialLeft; |
| 303 | + } while ( currentPosition.top === fakePosition.top && offset !== edgeCondition ) |
| 304 | + this.showCursor( this.documentView.getOffsetFromPosition( fakePosition ) ); |
318 | 305 | } |
| 306 | + return; |
319 | 307 | }; |
320 | 308 | |
321 | 309 | es.SurfaceView.prototype.drawSelection = function() { |