r102582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102581‎ | r102582 | r102583 >
Date:22:01, 9 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Added support for double click (to select word) and triple click (to select entire node) 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
@@ -18,12 +18,10 @@
1919 // Interaction state
2020 this.mouse = {
2121 selecting: false,
22 - clicks: 0,
23 - clickDelay: 500,
24 - clickTimeout: null,
25 - clickPosition: null,
26 - hotSpotRadius: 1,
27 - lastMovePosition: null
 22+ timer: null,
 23+ delta: 0,
 24+ clickTime: 0,
 25+ clickPosition: null
2826 };
2927 this.cursor = {
3028 $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ),
@@ -48,10 +46,29 @@
4947 var surfaceView = this,
5048 $document = $( document );
5149
52 - // MouseDown on surface
 50+ // MouseDown and DoubleClick on surface
5351 this.$.on( {
5452 'mousedown' : function(e) {
55 - return surfaceView.onMouseDown( 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+ }
5673 }
5774 } );
5875
@@ -111,23 +128,42 @@
112129 this.documentView.on('update', function() {alert(1);});
113130 };
114131
115 -es.SurfaceView.prototype.onMouseDown = function( e ) {
116 - if ( e.button === 0 /* left mouse button */ ) {
117 - this.mouse.selecting = true;
118 - this.selection.to = this.documentView.getOffsetFromEvent( e );
119 -
120 - if ( this.keyboard.keys.shift ) {
 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 ) {
 139+ this.documentView.drawSelection( this.selection );
 140+ 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+ );
121154 this.documentView.drawSelection( this.selection );
122155 this.hideCursor();
123 - } else {
124 - this.documentView.clearSelection();
125 - this.selection.from = this.selection.to;
126 - var position = es.Position.newFromEventPagePosition( e ),
127 - nodeView = this.documentView.getNodeFromOffset( this.selection.to, false );
128 - this.cursor.initialBias = position.left > nodeView.$.offset().left;
129 - this.showCursor();
130 - }
 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;
131166 }
 167+
132168 if ( !this.$input.is( ':focus' ) ) {
133169 this.$input.focus().select();
134170 }

Status & tagging log