r102604 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102603‎ | r102604 | r102605 >
Date:23:36, 9 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Another way of supporting double and triple clicks in VisualEditor
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
@@ -49,26 +49,7 @@
5050 // MouseDown and DoubleClick on surface
5151 this.$.on( {
5252 'mousedown' : function(e) {
53 - if ( e.button === 0 ) {
54 - if ( surfaceView.mouse.timer && surfaceView.mouse.clickPosition.near( es.Position.newFromEventScreenPosition( e ), 2 ) ) {
55 - clearTimeout( surfaceView.mouse.timer );
56 - surfaceView.mouse.timer = null;
57 - return surfaceView.onMouseDown( e, 3 );
58 - } else {
59 - surfaceView.mouse.delta = new Date().getTime() - surfaceView.mouse.clickTime;
60 - surfaceView.mouse.clickTime += surfaceView.mouse.delta;
61 - return surfaceView.onMouseDown( e, 1 );
62 - }
63 - }
64 - },
65 - 'dblclick' : function(e) {
66 - if ( e.button === 0 ) {
67 - surfaceView.mouse.timer = setTimeout( function () {
68 - surfaceView.mouse.timer = null;
69 - }, surfaceView.mouse.delta * 1.25 );
70 - surfaceView.mouse.clickPosition = es.Position.newFromEventScreenPosition( e );
71 - return surfaceView.onMouseDown( e, 2 );
72 - }
 53+ return surfaceView.onMouseDown( e );
7354 }
7455 } );
7556
@@ -128,42 +109,43 @@
129110 this.documentView.on('update', function() {alert(1);});
130111 };
131112
132 -es.SurfaceView.prototype.onMouseDown = function( e, clicks ) {
133 - switch ( clicks ) {
134 - case 1:
135 - this.mouse.selecting = true;
136 - this.selection.to = this.documentView.getOffsetFromEvent( e );
137 -
138 - if ( this.keyboard.keys.shift ) {
 113+es.SurfaceView.prototype.onMouseDown = function( e ) {
 114+ if ( e.button === 0 ) {
 115+ switch ( e.originalEvent.detail ) {
 116+ case 1: // single click
 117+ this.mouse.selecting = true;
 118+ this.selection.to = this.documentView.getOffsetFromEvent( e );
 119+ if ( this.keyboard.keys.shift ) {
 120+ this.documentView.drawSelection( this.selection );
 121+ this.hideCursor();
 122+ } else {
 123+ this.documentView.clearSelection();
 124+ this.selection.from = this.selection.to;
 125+ var position = es.Position.newFromEventPagePosition( e ),
 126+ nodeView = this.documentView.getNodeFromOffset( this.selection.to, false );
 127+ this.cursor.initialBias = position.left > nodeView.$.offset().left;
 128+ this.showCursor();
 129+ }
 130+ break;
 131+ case 2: // double click
 132+ this.selection = this.documentView.model.getWordBoundaries(
 133+ this.documentView.getOffsetFromEvent( e )
 134+ );
139135 this.documentView.drawSelection( this.selection );
140136 this.hideCursor();
141 - } else {
142 - this.documentView.clearSelection();
143 - this.selection.from = this.selection.to;
144 - var position = es.Position.newFromEventPagePosition( e ),
145 - nodeView = this.documentView.getNodeFromOffset( this.selection.to, false );
146 - this.cursor.initialBias = position.left > nodeView.$.offset().left;
147 - this.showCursor();
148 - }
149 - break;
150 - case 2:
151 - this.selection = this.documentView.model.getWordBoundaries(
152 - this.documentView.getOffsetFromEvent( e )
153 - );
154 - this.documentView.drawSelection( this.selection );
155 - this.hideCursor();
156 - break;
157 - case 3:
158 - var node = this.documentView.getNodeFromOffset(
159 - this.documentView.getOffsetFromEvent( e )
160 - );
161 - this.selection.from = this.documentView.getOffsetFromNode( node, false );
162 - this.selection.to = this.selection.from + node.getElementLength();
163 - this.documentView.drawSelection( this.selection );
164 - this.hideCursor();
165 - break;
 137+ break;
 138+ break;
 139+ default: // 3 and more
 140+ var node = this.documentView.getNodeFromOffset(
 141+ this.documentView.getOffsetFromEvent( e )
 142+ );
 143+ this.selection.from = this.documentView.getOffsetFromNode( node, false );
 144+ this.selection.to = this.selection.from + node.getElementLength() - 1;
 145+ this.documentView.drawSelection( this.selection );
 146+ this.hideCursor();
 147+ break;
 148+ }
166149 }
167 -
168150 if ( !this.$input.is( ':focus' ) ) {
169151 this.$input.focus().select();
170152 }

Status & tagging log