r100443 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100442‎ | r100443 | r100444 >
Date:20:06, 21 October 2011
Author:inez
Status:deferred
Tags:
Comment:
Way better working support for moving cursor up and down with arrow keys
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
@@ -40,7 +40,8 @@
4141 this.cursor = {
4242 $: $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ ),
4343 interval: null,
44 - offset: null
 44+ offset: null,
 45+ initialLeft: null
4546 };
4647
4748 // References for use in closures
@@ -181,6 +182,7 @@
182183 if ( !this.$input.is( ':focus' ) ) {
183184 this.$input.focus().select();
184185 }
 186+ this.cursor.initialLeft = null;
185187 return false;
186188 };
187189
@@ -272,49 +274,35 @@
273275 };
274276
275277 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;
289293
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;
295299 }
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 ) );
318305 }
 306+ return;
319307 };
320308
321309 es.SurfaceView.prototype.drawSelection = function() {

Status & tagging log