r102014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102013‎ | r102014 | r102015 >
Date:17:46, 4 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Fix cursor and selection
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
@@ -137,7 +137,7 @@
138138 es.SurfaceView.prototype.onMouseMove = function( e ) {
139139 if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
140140 this.selection.to = this.documentView.getOffsetFromEvent( e );
141 - this.drawSelection();
 141+ this.documentView.drawSelection( this.selection );
142142 if ( this.selection.getLength() ) {
143143 this.hideCursor();
144144 }
@@ -150,11 +150,6 @@
151151 }
152152 };
153153
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 -
159154 es.SurfaceView.prototype.onKeyDown = function( e ) {
160155 switch ( e.keyCode ) {
161156 case 16: // Shift
@@ -236,57 +231,51 @@
237232 es.SurfaceView.prototype.moveCursor = function( instruction ) {
238233 this.selection.normalize();
239234 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 {
241240 this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 );
242 - this.drawSelection();
 241+ this.documentView.drawSelection( this.selection );
243242 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();
250243 }
251244 } 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 {
254250 this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 );
255 - this.drawSelection();
 251+ this.documentView.drawSelection( this.selection );
256252 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();
263253 }
264254 } else if ( instruction === 'up' || instruction === 'down' ) {
265255 // ...
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();
271263 } 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 );
285266 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;
288273 this.documentView.clearSelection();
 274+ this.showCursor();
 275+ } else {
 276+ this.selection.to = offset;
 277+ this.documentView.drawSelection( this.selection );
 278+ this.hideCursor();
289279 }
290 -
291280 }
292281 };
293282

Status & tagging log