Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | default: // Insert content (maybe) |
144 | 144 | break; |
145 | 145 | } |
146 | | - return true; |
| 146 | + return false; |
147 | 147 | }; |
148 | 148 | |
149 | 149 | es.SurfaceView.prototype.onKeyUp = function( e ) { |
— | — | @@ -281,27 +281,39 @@ |
282 | 282 | this.showCursor( this.cursor.offset + 1 ); |
283 | 283 | this.cursor.initialLeft = null; |
284 | 284 | } else if ( direction === 'up' || direction === 'down' ) { |
285 | | - var currentPosition = this.documentView.getRenderedPosition( this.cursor.offset ); |
| 285 | + |
| 286 | + /* |
| 287 | + * Looks for the in-document character position that would match up with the same horizontal |
| 288 | + * position - jumping a few pixels up/down at a time until we reach the next/previous line |
| 289 | + */ |
| 290 | + |
| 291 | + var oldPosition = this.documentView.getRenderedPosition( this.cursor.offset ); |
| 292 | + |
286 | 293 | if ( this.cursor.initialLeft === null ) { |
287 | | - this.cursor.initialLeft = currentPosition.left; |
| 294 | + this.cursor.initialLeft = oldPosition.left; |
288 | 295 | } |
289 | | - var fakePosition = new es.Position( this.cursor.initialLeft, currentPosition.top ), |
290 | | - edgeCondition = ( direction === 'up' ) ? 0 : this.documentView.getLength(), |
| 296 | + |
| 297 | + var fakePosition = new es.Position( this.cursor.initialLeft, oldPosition.top ), |
| 298 | + i = 1, |
291 | 299 | offset, |
292 | | - i = 1; |
| 300 | + step, |
| 301 | + edge; |
| 302 | + |
| 303 | + if ( direction === 'up' ) { |
| 304 | + step = -5; |
| 305 | + edge = 0; |
| 306 | + } else { |
| 307 | + step = 5; |
| 308 | + edge = this.documentView.getLength(); |
| 309 | + } |
| 310 | + |
293 | 311 | do { |
294 | | - if ( direction == 'up' ) { |
295 | | - fakePosition.top -= i++ * 5; |
296 | | - } else { |
297 | | - fakePosition.top += i++ * 5; |
298 | | - } |
| 312 | + fakePosition.top += i++ * step; |
299 | 313 | offset = this.documentView.getOffsetFromPosition( fakePosition ); |
300 | | - if ( offset === edgeCondition ) { |
301 | | - return; |
302 | | - } |
303 | 314 | fakePosition = this.documentView.getRenderedPosition( offset ); |
304 | 315 | fakePosition.left = this.cursor.initialLeft; |
305 | | - } while ( currentPosition.top === fakePosition.top ); |
| 316 | + } while ( oldPosition.top === fakePosition.top && offset !== edge ); |
| 317 | + |
306 | 318 | this.showCursor( this.documentView.getOffsetFromPosition( fakePosition ) ); |
307 | 319 | } |
308 | 320 | return; |