r103404 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103403‎ | r103404 | r103405 >
Date:23:16, 16 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Basic support for enter key in heading and paragraphs
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
@@ -143,7 +143,7 @@
144144 if ( e.button === 0 ) { // left mouse button
145145
146146 var offset = this.documentView.getOffsetFromEvent( e );
147 -
 147+
148148 console.log('onMouseDown; offset: ' + offset);
149149
150150 if ( e.originalEvent.detail === 1 ) { // single click
@@ -356,6 +356,40 @@
357357 }
358358
359359 break;
 360+ case 13: // Enter
 361+ if ( this.selection.from === this.selection.to ) {
 362+ var node = this.documentView.getNodeFromOffset( this.selection.to, false ).model,
 363+ nodeType,
 364+ stack = [];
 365+
 366+ while ( node ) {
 367+ nodeType = node.getElementType();
 368+ stack.push(nodeType);
 369+ node = node.getParent();
 370+
 371+ if ( es.DocumentView.splitRules[ nodeType ].self === true ) {
 372+ nodeType = node.getElementType();
 373+ if ( es.DocumentView.splitRules[ nodeType ].children === true) {
 374+ break;
 375+ }
 376+ }
 377+ }
 378+
 379+ var temp = [];
 380+ for ( var i = 0; i < stack.length; i++ ) {
 381+ temp.push( { 'type' : '/' + stack[i] } );
 382+ }
 383+ for ( var i = stack.length - 1; i >= 0; i-- ) {
 384+ temp.push( { 'type' : stack[i] } );
 385+ }
 386+
 387+ var tx = this.documentView.model.prepareInsertion( this.selection.to, temp );
 388+ this.documentView.model.commit( tx );
 389+
 390+ //this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to+1, 1 );
 391+ //this.showCursor();
 392+ }
 393+ break;
360394 default: // Insert content (maybe)
361395 if ( this.keyboard.keydownTimeout ) {
362396 clearTimeout( this.keyboard.keydownTimeout );

Status & tagging log