r103857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103856‎ | r103857 | r103858 >
Date:22:55, 21 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Auto scroll to cursor is showCursor method
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
@@ -345,54 +345,7 @@
346346 this.handleDelete();
347347 break;
348348 case 13: // Enter
349 - if ( this.selection.from === this.selection.to ) {
350 - var tx,
351 - node = this.documentView.getNodeFromOffset( this.selection.to, false ),
352 - nodeOffset = this.documentView.getOffsetFromNode( node, false );
353 -
354 - if (
355 - nodeOffset + node.getContentLength() + 1 === this.selection.to &&
356 - node === es.DocumentViewNode.getSplitableNode( node )
357 - ) {
358 - tx = this.documentView.model.prepareInsertion(
359 - nodeOffset + node.getElementLength(),
360 - [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ]
361 - );
362 - this.documentView.model.commit( tx );
363 - this.selection.from = this.selection.to =
364 - nodeOffset + node.getElementLength() + 1;
365 - this.showCursor();
366 - } else {
367 - var stack = [],
368 - splitable = false;
369 -
370 - es.DocumentNode.traverseUpstream( node, function( node ) {
371 - var elementType = node.model.getElementType();
372 - if (
373 - splitable === true &&
374 - es.DocumentView.splitRules[ elementType ].children === true
375 - ) {
376 - return false;
377 - }
378 - stack.splice(
379 - stack.length / 2,
380 - 0,
381 - { 'type': '/' + elementType },
382 - {
383 - 'type': elementType,
384 - 'attributes': es.copyObject( node.model.element.attributes )
385 - }
386 - );
387 - splitable = es.DocumentView.splitRules[ elementType ].self;
388 - } );
389 - tx = this.documentView.model.prepareInsertion( this.selection.to, stack );
390 - this.documentView.model.commit( tx );
391 - this.selection.from = this.selection.to =
392 - this.documentView.getModel()
393 - .getRelativeContentOffset( this.selection.to, 1 );
394 - this.showCursor();
395 - }
396 - }
 349+ this.handleEnter();
397350 e.preventDefault();
398351 break;
399352 default: // Insert content (maybe)
@@ -491,6 +444,55 @@
492445 }
493446 };
494447
 448+es.SurfaceView.prototype.handleEnter = function() {
 449+ if ( this.selection.from !== this.selection.to ) {
 450+ this.handleDelete();
 451+ }
 452+ var node = this.documentView.getNodeFromOffset( this.selection.to, false ),
 453+ nodeOffset = this.documentView.getOffsetFromNode( node, false );
 454+
 455+ if (
 456+ nodeOffset + node.getContentLength() + 1 === this.selection.to &&
 457+ node === es.DocumentViewNode.getSplitableNode( node )
 458+ ) {
 459+ var tx = this.documentView.model.prepareInsertion(
 460+ nodeOffset + node.getElementLength(),
 461+ [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ]
 462+ );
 463+ this.documentView.model.commit( tx );
 464+ this.selection.from = this.selection.to = nodeOffset + node.getElementLength() + 1;
 465+ this.showCursor();
 466+ } else {
 467+ var stack = [],
 468+ splitable = false;
 469+
 470+ es.DocumentNode.traverseUpstream( node, function( node ) {
 471+ var elementType = node.model.getElementType();
 472+ if (
 473+ splitable === true &&
 474+ es.DocumentView.splitRules[ elementType ].children === true
 475+ ) {
 476+ return false;
 477+ }
 478+ stack.splice(
 479+ stack.length / 2,
 480+ 0,
 481+ { 'type': '/' + elementType },
 482+ {
 483+ 'type': elementType,
 484+ 'attributes': es.copyObject( node.model.element.attributes )
 485+ }
 486+ );
 487+ splitable = es.DocumentView.splitRules[ elementType ].self;
 488+ } );
 489+ var tx = this.documentView.model.prepareInsertion( this.selection.to, stack );
 490+ this.documentView.model.commit( tx );
 491+ this.selection.from = this.selection.to =
 492+ this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 );
 493+ this.showCursor();
 494+ }
 495+};
 496+
495497 es.SurfaceView.prototype.insertFromInput = function() {
496498 var val = this.$input.val();
497499 this.$input.val( '' );
@@ -511,8 +513,6 @@
512514 }
513515 };
514516
515 -
516 -
517517 /**
518518 * @param {String} direction up | down | left | right
519519 * @param {String} unit char | word | line | node | page
@@ -662,6 +662,15 @@
663663 'height': position.bottom - position.top
664664 });
665665
 666+ // Auto scroll to cursor
 667+ var inputTop = this.$input.offset().top,
 668+ inputBottom = inputTop + position.bottom - position.top;
 669+ if ( inputTop < this.dimensions.scrollTop ) {
 670+ this.$window.scrollTop( inputTop );
 671+ } else if ( inputBottom > ( this.dimensions.scrollTop + this.dimensions.height ) ) {
 672+ this.$window.scrollTop( inputBottom - this.dimensions.height );
 673+ }
 674+
666675 // cursor blinking
667676 if ( this.cursor.interval ) {
668677 clearInterval( this.cursor.interval );

Status & tagging log