r101875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101874‎ | r101875 | r101876 >
Date:20:27, 3 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Implementation of selecting elements with mouse and fix for drawSelection method in DocumentViewBranchNode (it was off by one)
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/bases/es.DocumentViewBranchNode.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/bases/es.DocumentViewBranchNode.js
@@ -40,8 +40,8 @@
4141 if ( nodes.length && this.children[i] === nodes[0].node ) {
4242 for ( var j = 0; j < nodes.length; j++ ) {
4343 nodes[j].node.drawSelection( nodes[j].range );
44 - i++;
4544 }
 45+ i += nodes.length - 1;
4646 } else {
4747 this.children[i].clearSelection();
4848 }
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -68,10 +68,10 @@
6969 $document.off( '.es-surfaceView' );
7070 $document.on({
7171 'mousemove.es-surfaceView': function(e) {
72 - //return surfaceView.onMouseMove( e );
 72+ return surfaceView.onMouseMove( e );
7373 },
7474 'mouseup.es-surfaceView': function(e) {
75 - //return surfaceView.onMouseUp( e );
 75+ return surfaceView.onMouseUp( e );
7676 },
7777 'keydown.es-surfaceView': function( e ) {
7878 return surfaceView.onKeyDown( e );
@@ -114,16 +114,49 @@
115115 };
116116
117117 es.SurfaceView.prototype.onMouseDown = function( e ) {
118 - var position = es.Position.newFromEventPagePosition( e ),
119 - offset = this.documentView.getOffsetFromEvent( e ),
120 - nodeView = this.documentView.getNodeFromOffset( offset, false );
121 - this.showCursor( offset, position.left > nodeView.$.offset().left );
 118+ if ( e.button === 0 /* left mouse button */ ) {
 119+ var position = es.Position.newFromEventPagePosition( e ),
 120+ offset = this.documentView.getOffsetFromEvent( e ),
 121+ nodeView = this.documentView.getNodeFromOffset( offset, false );
 122+ this.showCursor( offset, position.left > nodeView.$.offset().left );
 123+ this.mouse.selecting = true;
 124+ if ( !this.keyboard.keys.shift ) {
 125+ this.selection.from = offset;
 126+ }
 127+ this.selection.to = offset;
 128+ this.drawSelection();
 129+ }
122130 if ( !this.$input.is( ':focus' ) ) {
123131 this.$input.focus().select();
124132 }
 133+ this.cursor.initialLeft = null;
125134 return false;
126135 };
127136
 137+es.SurfaceView.prototype.onMouseMove = function( e ) {
 138+ if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
 139+ this.hideCursor();
 140+ this.selection.to = this.documentView.getOffsetFromEvent( e );
 141+ if ( !this.drawSelection() ) {
 142+ this.showCursor();
 143+ }
 144+ }
 145+};
 146+
 147+es.SurfaceView.prototype.onMouseUp = function( e ) {
 148+ if ( e.button === 0 /* left mouse button */ && this.selection.to ) {
 149+ if ( this.drawSelection() ) {
 150+ this.hideCursor();
 151+ }
 152+ }
 153+ this.mouse.selecting = false;
 154+};
 155+
 156+es.SurfaceView.prototype.drawSelection = function() {
 157+ this.documentView.drawSelection( new es.Range( this.selection.from, this.selection.to ) );
 158+ return this.selection.from !== this.selection.to;
 159+};
 160+
128161 es.SurfaceView.prototype.onKeyDown = function( e ) {
129162 switch ( e.keyCode ) {
130163 case 16: // Shift

Status & tagging log