r100474 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100473‎ | r100474 | r100475 >
Date:23:17, 21 October 2011
Author:inez
Status:deferred
Tags:
Comment:
Refactor to moveCursor method
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -142,7 +142,7 @@
143143 default: // Insert content (maybe)
144144 break;
145145 }
146 - return true;
 146+ return false;
147147 };
148148
149149 es.SurfaceView.prototype.onKeyUp = function( e ) {
@@ -281,27 +281,39 @@
282282 this.showCursor( this.cursor.offset + 1 );
283283 this.cursor.initialLeft = null;
284284 } 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+
286293 if ( this.cursor.initialLeft === null ) {
287 - this.cursor.initialLeft = currentPosition.left;
 294+ this.cursor.initialLeft = oldPosition.left;
288295 }
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,
291299 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+
293311 do {
294 - if ( direction == 'up' ) {
295 - fakePosition.top -= i++ * 5;
296 - } else {
297 - fakePosition.top += i++ * 5;
298 - }
 312+ fakePosition.top += i++ * step;
299313 offset = this.documentView.getOffsetFromPosition( fakePosition );
300 - if ( offset === edgeCondition ) {
301 - return;
302 - }
303314 fakePosition = this.documentView.getRenderedPosition( offset );
304315 fakePosition.left = this.cursor.initialLeft;
305 - } while ( currentPosition.top === fakePosition.top );
 316+ } while ( oldPosition.top === fakePosition.top && offset !== edge );
 317+
306318 this.showCursor( this.documentView.getOffsetFromPosition( fakePosition ) );
307319 }
308320 return;

Status & tagging log