r103574 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103573‎ | r103574 | r103575 >
Date:06:17, 18 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Proper handling for "enter" key
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
@@ -322,6 +322,42 @@
323323 case 46: // Delete
324324 break;
325325 case 13: // Enter
 326+ if ( this.selection.from === this.selection.to ) {
 327+ var node = this.documentView.getNodeFromOffset( this.selection.to, false ),
 328+ nodeOffset = this.documentView.getOffsetFromNode( node, false );
 329+
 330+ if ( nodeOffset + node.getContentLength() + 1 === this.selection.to && node === es.DocumentViewNode.getSplitableNode( node ) ) {
 331+ var tx = this.documentView.model.prepareInsertion(
 332+ nodeOffset + node.getElementLength(),
 333+ [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ]
 334+ );
 335+ this.documentView.model.commit( tx );
 336+ this.selection.from = this.selection.to = nodeOffset + node.getElementLength() + 1;
 337+ this.showCursor();
 338+ } else {
 339+ var stack = [],
 340+ splitable = false;
 341+
 342+ es.DocumentNode.traverseUpstream( node, function( node ) {
 343+ var elementType = node.model.getElementType();
 344+ if ( splitable === true && es.DocumentView.splitRules[ elementType ].children === true ) {
 345+ return false;
 346+ }
 347+ stack.splice(
 348+ stack.length / 2,
 349+ 0,
 350+ { 'type': '/' + elementType },
 351+ { 'type': elementType, 'attributes': es.copyObject( node.model.element.attributes ) }
 352+ );
 353+ splitable = es.DocumentView.splitRules[ elementType ].self;
 354+ } );
 355+ var tx = this.documentView.model.prepareInsertion( this.selection.to, stack );
 356+ this.documentView.model.commit( tx );
 357+ this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 );
 358+ this.showCursor();
 359+ }
 360+ }
 361+ e.preventDefault();
326362 break;
327363 default: // Insert content (maybe)
328364 if ( this.keyboard.keydownTimeout ) {

Status & tagging log