Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -18,12 +18,10 @@ |
19 | 19 | // Interaction state |
20 | 20 | this.mouse = { |
21 | 21 | 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 |
28 | 26 | }; |
29 | 27 | this.cursor = { |
30 | 28 | $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ), |
— | — | @@ -48,10 +46,29 @@ |
49 | 47 | var surfaceView = this, |
50 | 48 | $document = $( document ); |
51 | 49 | |
52 | | - // MouseDown on surface |
| 50 | + // MouseDown and DoubleClick on surface |
53 | 51 | this.$.on( { |
54 | 52 | '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 | + } |
56 | 73 | } |
57 | 74 | } ); |
58 | 75 | |
— | — | @@ -111,23 +128,42 @@ |
112 | 129 | this.documentView.on('update', function() {alert(1);}); |
113 | 130 | }; |
114 | 131 | |
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 | + ); |
121 | 154 | this.documentView.drawSelection( this.selection ); |
122 | 155 | 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; |
131 | 166 | } |
| 167 | + |
132 | 168 | if ( !this.$input.is( ':focus' ) ) { |
133 | 169 | this.$input.focus().select(); |
134 | 170 | } |