Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -17,11 +17,8 @@ |
18 | 18 | |
19 | 19 | // Interaction state |
20 | 20 | this.mouse = { |
21 | | - selecting: false, |
22 | | - timer: null, |
23 | | - delta: 0, |
24 | | - clickTime: 0, |
25 | | - clickPosition: null |
| 21 | + selectingMode: null, |
| 22 | + selectedRange: null |
26 | 23 | }; |
27 | 24 | this.cursor = { |
28 | 25 | $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ), |
— | — | @@ -110,11 +107,13 @@ |
111 | 108 | }; |
112 | 109 | |
113 | 110 | es.SurfaceView.prototype.onMouseDown = function( e ) { |
114 | | - if ( e.button === 0 ) { |
| 111 | + if ( e.button === 0 /* left mouse button */ ) { |
115 | 112 | switch ( e.originalEvent.detail ) { |
116 | 113 | case 1: // single click |
117 | | - this.mouse.selecting = true; |
| 114 | + this.mouse.selectingMode = 1; |
| 115 | + |
118 | 116 | this.selection.to = this.documentView.getOffsetFromEvent( e ); |
| 117 | + console.log(this.selection.to); |
119 | 118 | if ( this.keyboard.keys.shift ) { |
120 | 119 | this.documentView.drawSelection( this.selection ); |
121 | 120 | this.hideCursor(); |
— | — | @@ -128,21 +127,26 @@ |
129 | 128 | } |
130 | 129 | break; |
131 | 130 | case 2: // double click |
| 131 | + this.mouse.selectingMode = 2; |
| 132 | + |
132 | 133 | this.selection = this.documentView.model.getWordBoundaries( |
133 | 134 | this.documentView.getOffsetFromEvent( e ) |
134 | 135 | ); |
135 | 136 | this.documentView.drawSelection( this.selection ); |
136 | 137 | this.hideCursor(); |
| 138 | + this.mouse.selectedRange = new es.Range( this.selection.from, this.selection.to ); |
137 | 139 | break; |
138 | | - break; |
139 | 140 | default: // 3 and more |
| 141 | + this.mouse.selectingMode = 3; |
| 142 | + |
140 | 143 | var node = this.documentView.getNodeFromOffset( |
141 | 144 | this.documentView.getOffsetFromEvent( e ) |
142 | 145 | ); |
143 | 146 | this.selection.from = this.documentView.getOffsetFromNode( node, false ); |
144 | 147 | this.selection.to = this.selection.from + node.getElementLength() - 1; |
145 | 148 | this.documentView.drawSelection( this.selection ); |
146 | | - this.hideCursor(); |
| 149 | + this.hideCursor(); |
| 150 | + this.mouse.selectedRange = new es.Range( this.selection.from, this.selection.to ); |
147 | 151 | break; |
148 | 152 | } |
149 | 153 | } |
— | — | @@ -154,18 +158,81 @@ |
155 | 159 | }; |
156 | 160 | |
157 | 161 | es.SurfaceView.prototype.onMouseMove = function( e ) { |
158 | | - if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) { |
159 | | - this.selection.to = this.documentView.getOffsetFromEvent( e ); |
| 162 | + if ( e.button === 0 /* left mouse button */ && this.mouse.selectingMode ) { |
| 163 | + if ( this.mouse.selectingMode === 1 ) { |
| 164 | + this.selection.to = this.documentView.getOffsetFromEvent( e ); |
| 165 | + } else if ( this.mouse.selectingMode === 2 ) { |
| 166 | + var wordBoundaries = this.documentView.model.getWordBoundaries( |
| 167 | + this.documentView.getOffsetFromEvent( e ) |
| 168 | + ); |
| 169 | + if ( wordBoundaries.to <= this.mouse.selectedRange.from ) { |
| 170 | + this.selection.to = wordBoundaries.from; |
| 171 | + this.selection.from = this.mouse.selectedRange.to; |
| 172 | + } else { |
| 173 | + this.selection.from = this.mouse.selectedRange.from; |
| 174 | + this.selection.to = wordBoundaries.to; |
| 175 | + } |
| 176 | + } else if ( this.mouse.selectingMode === 3 ) { |
| 177 | + var node = this.documentView.getNodeFromOffset( |
| 178 | + this.documentView.getOffsetFromEvent( e ) |
| 179 | + ); |
| 180 | + var nodeBoundaries = new es.Range(); |
| 181 | + nodeBoundaries.from = this.documentView.getOffsetFromNode( node, false ); |
| 182 | + nodeBoundaries.to = nodeBoundaries.from + node.getElementLength() - 1; |
| 183 | + |
| 184 | + if ( nodeBoundaries.to <= this.mouse.selectedRange.from ) { |
| 185 | + this.selection.to = nodeBoundaries.from; |
| 186 | + this.selection.from = this.mouse.selectedRange.to; |
| 187 | + } else { |
| 188 | + this.selection.from = this.mouse.selectedRange.from; |
| 189 | + this.selection.to = nodeBoundaries.to; |
| 190 | + } |
| 191 | + } |
160 | 192 | this.documentView.drawSelection( this.selection ); |
161 | 193 | if ( this.selection.getLength() ) { |
162 | 194 | this.hideCursor(); |
| 195 | + } |
| 196 | + } |
| 197 | + return; |
| 198 | + |
| 199 | + if ( e.button === 0 /* left mouse button */ && this.mouse.selected ) { |
| 200 | + |
| 201 | + var offset = this.documentView.getOffsetFromEvent( e ); |
| 202 | + if ( this.mouse.selected.containsOffset( offset ) ) { |
| 203 | + //return; |
163 | 204 | } |
| 205 | + var wordBoundaries = this.documentView.model.getWordBoundaries( offset ); |
| 206 | + if ( wordBoundaries.to <= this.mouse.selected.from ) { |
| 207 | + this.selection.to = wordBoundaries.from; |
| 208 | + this.selection.from = this.mouse.selected.to; |
| 209 | + } else { |
| 210 | + this.selection.from = this.mouse.selected.from; |
| 211 | + this.selection.to = wordBoundaries.to; |
| 212 | + } |
| 213 | + |
| 214 | + /* |
| 215 | + var to = this.documentView.getOffsetFromEvent( e ); |
| 216 | + |
| 217 | + if ( to <= this.mouse.selected.from ) { |
| 218 | + this.selection.to = to; |
| 219 | + this.selection.from = this.mouse.selected.to; |
| 220 | + } else if ( to >= this.mouse.selected.to ) { |
| 221 | + this.selection.from = this.mouse.selected.from; |
| 222 | + this.selection.to = to; |
| 223 | + } |
| 224 | + */ |
| 225 | + |
| 226 | + this.documentView.drawSelection( this.selection ); |
| 227 | + |
| 228 | + } else if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) { |
| 229 | + this.selection.to = this.documentView.getOffsetFromEvent( e ); |
| 230 | + |
164 | 231 | } |
165 | 232 | }; |
166 | 233 | |
167 | 234 | es.SurfaceView.prototype.onMouseUp = function( e ) { |
168 | 235 | if ( e.button === 0 /* left mouse button */ ) { |
169 | | - this.mouse.selecting = false; |
| 236 | + this.mouse.selectingMode = this.mouse.selectedRange = null; |
170 | 237 | } |
171 | 238 | }; |
172 | 239 | |