Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | es.SurfaceView.prototype.onMouseMove = function( e ) { |
139 | 139 | if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) { |
140 | 140 | this.selection.to = this.documentView.getOffsetFromEvent( e ); |
141 | | - this.drawSelection(); |
| 141 | + this.documentView.drawSelection( this.selection ); |
142 | 142 | if ( this.selection.getLength() ) { |
143 | 143 | this.hideCursor(); |
144 | 144 | } |
— | — | @@ -150,11 +150,6 @@ |
151 | 151 | } |
152 | 152 | }; |
153 | 153 | |
154 | | -es.SurfaceView.prototype.drawSelection = function() { |
155 | | - this.documentView.drawSelection( new es.Range( this.selection.from, this.selection.to ) ); |
156 | | - return this.selection.from !== this.selection.to; |
157 | | -}; |
158 | | - |
159 | 154 | es.SurfaceView.prototype.onKeyDown = function( e ) { |
160 | 155 | switch ( e.keyCode ) { |
161 | 156 | case 16: // Shift |
— | — | @@ -236,57 +231,51 @@ |
237 | 232 | es.SurfaceView.prototype.moveCursor = function( instruction ) { |
238 | 233 | this.selection.normalize(); |
239 | 234 | if ( instruction === 'left') { |
240 | | - if ( this.keyboard.keys.shift ) { |
| 235 | + if ( !this.keyboard.keys.shift ) { |
| 236 | + this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.getLength() ? this.selection.start : this.selection.to, -1 ); |
| 237 | + this.documentView.clearSelection(); |
| 238 | + this.showCursor(); |
| 239 | + } else { |
241 | 240 | this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 ); |
242 | | - this.drawSelection(); |
| 241 | + this.documentView.drawSelection( this.selection ); |
243 | 242 | this.hideCursor(); |
244 | | - } else { |
245 | | - this.showCursor( |
246 | | - this.documentView.getModel().getRelativeContentOffset( this.selection.getLength() ? this.selection.start : this.selection.to, -1 ) |
247 | | - ); |
248 | | - this.selection.from = this.selection.to; |
249 | | - this.documentView.clearSelection(); |
250 | 243 | } |
251 | 244 | } else if ( instruction === 'right' ) { |
252 | | - |
253 | | - if ( this.keyboard.keys.shift ) { |
| 245 | + if ( !this.keyboard.keys.shift ) { |
| 246 | + this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.getLength() ? this.selection.end : this.selection.to, 1 ); |
| 247 | + this.documentView.clearSelection(); |
| 248 | + this.showCursor(); |
| 249 | + } else { |
254 | 250 | this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 ); |
255 | | - this.drawSelection(); |
| 251 | + this.documentView.drawSelection( this.selection ); |
256 | 252 | this.hideCursor(); |
257 | | - } else { |
258 | | - this.showCursor( |
259 | | - this.documentView.getModel().getRelativeContentOffset( this.selection.getLength() ? this.selection.end : this.selection.to, 1 ) |
260 | | - ); |
261 | | - this.selection.from = this.selection.to; |
262 | | - this.documentView.clearSelection(); |
263 | 253 | } |
264 | 254 | } else if ( instruction === 'up' || instruction === 'down' ) { |
265 | 255 | // ... |
266 | | - } else if ( instruction === 'home' || instruction === 'end' ) { |
267 | | - var offset; |
268 | | - if ( this.cursor.initialBias ) { |
269 | | - offset = this.documentView.getModel().getRelativeContentOffset( |
270 | | - this.selection.to, -1 ); |
| 256 | + } else if ( instruction === 'home' ) { |
| 257 | + var offset = this.cursor.initialBias ? this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 ) : this.selection.to; |
| 258 | + offset = this.documentView.getRenderedLineRangeFromOffset( offset ).start; |
| 259 | + if ( !this.keyboard.keys.shift ) { |
| 260 | + this.selection.from = this.selection.to = offset; |
| 261 | + this.documentView.clearSelection(); |
| 262 | + this.showCursor(); |
271 | 263 | } else { |
272 | | - offset = this.selection.to; |
273 | | - } |
274 | | - |
275 | | - |
276 | | - |
277 | | - if ( instruction === 'home' ) { |
278 | | - this.showCursor( |
279 | | - this.documentView.getRenderedLineRangeFromOffset( offset ).start, false ); |
280 | | - } else { // end |
281 | | - this.showCursor( this.documentView.getRenderedLineRangeFromOffset( offset ).end, true ); |
282 | | - } |
283 | | - if ( this.keyboard.keys.shift ) { |
284 | | - this.drawSelection(); |
| 264 | + this.selection.to = offset; |
| 265 | + this.documentView.drawSelection( this.selection ); |
285 | 266 | this.hideCursor(); |
286 | | - } else { |
287 | | - this.selection.from = this.selection.to; |
| 267 | + } |
| 268 | + } else if ( instruction === 'end' ) { |
| 269 | + var offset = this.cursor.initialBias ? this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 ) : this.selection.to; |
| 270 | + offset = this.documentView.getRenderedLineRangeFromOffset( offset ).end; |
| 271 | + if ( !this.keyboard.keys.shift ) { |
| 272 | + this.selection.from = this.selection.to = offset; |
288 | 273 | this.documentView.clearSelection(); |
| 274 | + this.showCursor(); |
| 275 | + } else { |
| 276 | + this.selection.to = offset; |
| 277 | + this.documentView.drawSelection( this.selection ); |
| 278 | + this.hideCursor(); |
289 | 279 | } |
290 | | - |
291 | 280 | } |
292 | 281 | }; |
293 | 282 | |