r103635 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103634‎ | r103635 | r103636 >
Date:03:07, 19 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Improve logic for moving cursor up and down - especially in case of initialBias - code has to be refactored.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -323,7 +323,6 @@
324324 }
325325 break;
326326 case 8: // Backspace
327 - this.cursor.initialBias = this.cursor.initialLeft = null;
328327 if ( this.selection.from === this.selection.to ) {
329328 var sourceOffset = this.selection.to,
330329 targetOffset = this.documentView.getModel().getRelativeContentOffset( sourceOffset, -1),
@@ -370,7 +369,6 @@
371370 }
372371 break;
373372 case 46: // Delete
374 - this.cursor.initialBias = this.cursor.initialLeft = null;
375373 if ( this.selection.from === this.selection.to ) {
376374 var sourceOffset = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1),
377375 targetOffset = this.selection.to,
@@ -415,7 +413,6 @@
416414 }
417415 break;
418416 case 13: // Enter
419 - this.cursor.initialBias = this.cursor.initialLeft = null;
420417 if ( this.selection.from === this.selection.to ) {
421418 var node = this.documentView.getNodeFromOffset( this.selection.to, false ),
422419 nodeOffset = this.documentView.getOffsetFromNode( node, false );
@@ -454,7 +451,6 @@
455452 e.preventDefault();
456453 break;
457454 default: // Insert content (maybe)
458 - this.cursor.initialBias = this.cursor.initialLeft = null;
459455 if ( this.keyboard.keydownTimeout ) {
460456 clearTimeout( this.keyboard.keydownTimeout );
461457 }
@@ -578,6 +574,7 @@
579575 this.selection.to,
580576 this.cursor.initialBias
581577 );
 578+
582579 if ( this.cursor.initialLeft === null ) {
583580 this.cursor.initialLeft = position.left;
584581 }
@@ -585,6 +582,9 @@
586583 i = 0,
587584 step = direction === 'up' ? -5 : 5,
588585 top = this.$.position().top;
 586+
 587+ this.cursor.initialBias = position.left > this.documentView.getNodeFromOffset( this.selection.to, false ).contentView.$.offset().left;
 588+
589589 do {
590590 fakePosition.top += ++i * step;
591591 if ( fakePosition.top < top ) {
@@ -592,29 +592,10 @@
593593 } else if (fakePosition.top > top + this.dimensions.height + this.dimensions.scrollTop ) {
594594 break;
595595 }
596 - offset = this.documentView.getOffsetFromRenderedPosition( fakePosition );
597 - fakePosition1 = this.documentView.getRenderedPositionFromOffset(
598 - offset,
599 - false
 596+ fakePosition = this.documentView.getRenderedPositionFromOffset(
 597+ this.documentView.getOffsetFromRenderedPosition( fakePosition ),
 598+ this.cursor.initialBias
600599 );
601 - fakePosition2 = this.documentView.getRenderedPositionFromOffset(
602 - offset,
603 - true
604 - );
605 -
606 - if(this.cursor.initialBias) {
607 - if(fakePosition1.top != fakePosition2.top) {
608 - fakePosition = fakePosition2;
609 - newBias = true;
610 - } else {
611 - fakePosition = fakePosition1;
612 - //newBias = true;
613 - }
614 - } else {
615 - fakePosition = fakePosition1;
616 - newBias = false;
617 - }
618 -
619600 fakePosition.left = this.cursor.initialLeft;
620601 } while ( position.top === fakePosition.top );
621602 to = this.documentView.getOffsetFromRenderedPosition( fakePosition );
@@ -623,12 +604,8 @@
624605 break;
625606 }
626607
627 - if(typeof newBias !== 'undefined') {
628 - this.cursor.initialBias = newBias;
629 - }
630 -
631608 if( direction != 'up' && direction != 'down' ) {
632 - this.cursor.initialBias = direction === 'right' && unit === 'line' ? true : false;
 609+ this.cursor.initialBias = direction === 'right' && unit === 'line' ? true : false;
633610 }
634611
635612 if ( this.keyboard.keys.shift && this.selection.from !== to) {

Status & tagging log