r103851 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103850‎ | r103851 | r103852 >
Date:22:43, 21 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Cleaned up some issues with scoping, line ending, variable redeclaration, etc.
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
@@ -346,16 +346,21 @@
347347 break;
348348 case 13: // Enter
349349 if ( this.selection.from === this.selection.to ) {
350 - var node = this.documentView.getNodeFromOffset( this.selection.to, false ),
 350+ var tx,
 351+ node = this.documentView.getNodeFromOffset( this.selection.to, false ),
351352 nodeOffset = this.documentView.getOffsetFromNode( node, false );
352 -
353 - if ( nodeOffset + node.getContentLength() + 1 === this.selection.to && node === es.DocumentViewNode.getSplitableNode( node ) ) {
354 - var tx = this.documentView.model.prepareInsertion(
 353+
 354+ if (
 355+ nodeOffset + node.getContentLength() + 1 === this.selection.to &&
 356+ node === es.DocumentViewNode.getSplitableNode( node )
 357+ ) {
 358+ tx = this.documentView.model.prepareInsertion(
355359 nodeOffset + node.getElementLength(),
356360 [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ]
357361 );
358362 this.documentView.model.commit( tx );
359 - this.selection.from = this.selection.to = nodeOffset + node.getElementLength() + 1;
 363+ this.selection.from = this.selection.to =
 364+ nodeOffset + node.getElementLength() + 1;
360365 this.showCursor();
361366 } else {
362367 var stack = [],
@@ -363,20 +368,28 @@
364369
365370 es.DocumentNode.traverseUpstream( node, function( node ) {
366371 var elementType = node.model.getElementType();
367 - if ( splitable === true && es.DocumentView.splitRules[ elementType ].children === true ) {
 372+ if (
 373+ splitable === true &&
 374+ es.DocumentView.splitRules[ elementType ].children === true
 375+ ) {
368376 return false;
369377 }
370378 stack.splice(
371379 stack.length / 2,
372380 0,
373381 { 'type': '/' + elementType },
374 - { 'type': elementType, 'attributes': es.copyObject( node.model.element.attributes ) }
 382+ {
 383+ 'type': elementType,
 384+ 'attributes': es.copyObject( node.model.element.attributes )
 385+ }
375386 );
376387 splitable = es.DocumentView.splitRules[ elementType ].self;
377388 } );
378 - var tx = this.documentView.model.prepareInsertion( this.selection.to, stack );
 389+ tx = this.documentView.model.prepareInsertion( this.selection.to, stack );
379390 this.documentView.model.commit( tx );
380 - this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 );
 391+ this.selection.from = this.selection.to =
 392+ this.documentView.getModel()
 393+ .getRelativeContentOffset( this.selection.to, 1 );
381394 this.showCursor();
382395 }
383396 }
@@ -410,27 +423,32 @@
411424 };
412425
413426 es.SurfaceView.prototype.handleDelete = function( backspace ) {
 427+ var sourceOffset,
 428+ targetOffset,
 429+ sourceSplitableNode,
 430+ targetSplitableNode,
 431+ tx;
414432 if ( this.selection.from === this.selection.to ) {
415433 if ( backspace ) {
416 - var sourceOffset = this.selection.to,
417 - targetOffset = this.documentView.getModel().getRelativeContentOffset(
418 - sourceOffset,
419 - -1
420 - );
 434+ sourceOffset = this.selection.to;
 435+ targetOffset = this.documentView.getModel().getRelativeContentOffset(
 436+ sourceOffset,
 437+ -1
 438+ );
421439 } else {
422 - var sourceOffset = this.documentView.getModel().getRelativeContentOffset(
423 - this.selection.to,
424 - 1
425 - ),
426 - targetOffset = this.selection.to;
 440+ sourceOffset = this.documentView.getModel().getRelativeContentOffset(
 441+ this.selection.to,
 442+ 1
 443+ );
 444+ targetOffset = this.selection.to;
427445 }
428446
429447 var sourceNode = this.documentView.getNodeFromOffset( sourceOffset, false ),
430448 targetNode = this.documentView.getNodeFromOffset( targetOffset, false );
431449
432450 if ( sourceNode.model.getElementType() === targetNode.model.getElementType() ) {
433 - var sourceSplitableNode = es.DocumentViewNode.getSplitableNode( sourceNode ),
434 - targetSplitableNode = es.DocumentViewNode.getSplitableNode( targetNode );
 451+ sourceSplitableNode = es.DocumentViewNode.getSplitableNode( sourceNode );
 452+ targetSplitableNode = es.DocumentViewNode.getSplitableNode( targetNode );
435453 }
436454
437455 this.selection.from = this.selection.to = targetOffset;
@@ -439,12 +457,12 @@
440458 if ( sourceNode === targetNode ||
441459 ( typeof sourceSplitableNode !== 'undefined' &&
442460 sourceSplitableNode.getParent() === targetSplitableNode.getParent() ) ) {
443 - var tx = this.documentView.model.prepareRemoval(
 461+ tx = this.documentView.model.prepareRemoval(
444462 new es.Range( targetOffset, sourceOffset )
445463 );
446464 this.documentView.model.commit ( tx );
447465 } else {
448 - var tx = this.documentView.model.prepareInsertion(
 466+ tx = this.documentView.model.prepareInsertion(
449467 targetOffset, sourceNode.model.getContent()
450468 );
451469 this.documentView.model.commit( tx );
@@ -465,7 +483,7 @@
466484 }
467485 } else {
468486 // selection removal
469 - var tx = this.documentView.model.prepareRemoval( this.selection );
 487+ tx = this.documentView.model.prepareRemoval( this.selection );
470488 this.documentView.model.commit( tx );
471489 this.documentView.clearSelection();
472490 this.selection.from = this.selection.to = this.selection.start;
@@ -477,14 +495,15 @@
478496 var val = this.$input.val();
479497 this.$input.val( '' );
480498 if ( val.length > 0 ) {
 499+ var tx;
481500 if ( this.selection.from != this.selection.to ) {
482 - var tx = this.documentView.model.prepareRemoval( this.selection );
 501+ tx = this.documentView.model.prepareRemoval( this.selection );
483502 this.documentView.model.commit( tx );
484503 this.documentView.clearSelection();
485 - this.selection.from = this.selection.to = Math.min( this.selection.from, this.selection.to );
 504+ this.selection.from = this.selection.to =
 505+ Math.min( this.selection.from, this.selection.to );
486506 }
487 -
488 - var tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') );
 507+ tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') );
489508 this.documentView.model.commit ( tx );
490509 this.selection.from += val.length;
491510 this.selection.to += val.length;
@@ -503,7 +522,8 @@
504523 this.cursor.initialLeft = null;
505524 }
506525
507 - var to;
 526+ var to,
 527+ offset;
508528
509529 switch ( direction ) {
510530 case 'left':
@@ -511,7 +531,6 @@
512532 switch ( unit ) {
513533 case 'char':
514534 case 'word':
515 - var offset;
516535 if ( this.keyboard.keys.shift || this.selection.from === this.selection.to ) {
517536 offset = this.selection.to;
518537 } else {
@@ -531,7 +550,7 @@
532551 }
533552 break;
534553 case 'line':
535 - var offset = this.cursor.initialBias ?
 554+ offset = this.cursor.initialBias ?
536555 this.documentView.getModel().getRelativeContentOffset(
537556 this.selection.to,
538557 -1) :
@@ -579,13 +598,18 @@
580599 step = direction === 'up' ? -5 : 5,
581600 top = this.$.position().top;
582601
583 - this.cursor.initialBias = position.left > this.documentView.getNodeFromOffset( this.selection.to, false ).contentView.$.offset().left;
 602+ this.cursor.initialBias = position.left > this.documentView.getNodeFromOffset(
 603+ this.selection.to, false
 604+ ).contentView.$.offset().left;
584605
585606 do {
586607 fakePosition.top += ++i * step;
587608 if ( fakePosition.top < top ) {
588609 break;
589 - } else if (fakePosition.top > top + this.dimensions.height + this.dimensions.scrollTop ) {
 610+ } else if (
 611+ fakePosition.top > top + this.dimensions.height +
 612+ this.dimensions.scrollTop
 613+ ) {
590614 break;
591615 }
592616 fakePosition = this.documentView.getRenderedPositionFromOffset(

Status & tagging log