https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102014

Revision: 102014
Author:   inez
Date:     2011-11-04 17:46:30 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Fix cursor and selection

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js

Modified: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
===================================================================
--- trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js    
2011-11-04 17:32:30 UTC (rev 102013)
+++ trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js    
2011-11-04 17:46:30 UTC (rev 102014)
@@ -137,7 +137,7 @@
 es.SurfaceView.prototype.onMouseMove = function( e ) {
        if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
                this.selection.to = this.documentView.getOffsetFromEvent( e );
-               this.drawSelection();
+               this.documentView.drawSelection( this.selection );
                if ( this.selection.getLength() ) {
                        this.hideCursor();
                }
@@ -150,11 +150,6 @@
        }
 };
 
-es.SurfaceView.prototype.drawSelection = function() {
-       this.documentView.drawSelection( new es.Range( this.selection.from, 
this.selection.to ) );
-       return this.selection.from !== this.selection.to;
-};
-
 es.SurfaceView.prototype.onKeyDown = function( e ) {
        switch ( e.keyCode ) {
                case 16: // Shift
@@ -236,57 +231,51 @@
 es.SurfaceView.prototype.moveCursor = function( instruction ) {
        this.selection.normalize();
        if ( instruction === 'left') {
-               if ( this.keyboard.keys.shift ) {
+               if ( !this.keyboard.keys.shift ) {
+                       this.selection.from = this.selection.to = 
this.documentView.getModel().getRelativeContentOffset( 
this.selection.getLength() ? this.selection.start : this.selection.to, -1 );
+                       this.documentView.clearSelection();
+                       this.showCursor();
+               } else {
                        this.selection.to = 
this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 );
-                       this.drawSelection();
+                       this.documentView.drawSelection( this.selection );
                        this.hideCursor();
-               } else {
-                       this.showCursor(
-                               
this.documentView.getModel().getRelativeContentOffset( 
this.selection.getLength() ? this.selection.start : this.selection.to, -1 )
-                       );
-                       this.selection.from = this.selection.to;
-                       this.documentView.clearSelection();
                }
        } else if ( instruction === 'right' ) {
-
-               if ( this.keyboard.keys.shift ) {
+               if ( !this.keyboard.keys.shift ) {
+                       this.selection.from = this.selection.to = 
this.documentView.getModel().getRelativeContentOffset( 
this.selection.getLength() ? this.selection.end : this.selection.to, 1 );
+                       this.documentView.clearSelection();
+                       this.showCursor();
+               } else {
                        this.selection.to = 
this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 );
-                       this.drawSelection();
+                       this.documentView.drawSelection( this.selection );
                        this.hideCursor();
-               } else {
-                       this.showCursor(
-                               
this.documentView.getModel().getRelativeContentOffset( 
this.selection.getLength() ? this.selection.end : this.selection.to, 1 )
-                       );
-                       this.selection.from = this.selection.to;
-                       this.documentView.clearSelection();
                }
        } else if ( instruction === 'up' || instruction === 'down' ) {
                // ...
-       } else if ( instruction === 'home' || instruction === 'end' ) {
-               var offset;
-               if ( this.cursor.initialBias ) {
-                       offset = 
this.documentView.getModel().getRelativeContentOffset(
-                               this.selection.to, -1 );
+       } else if ( instruction === 'home' ) {
+               var offset = this.cursor.initialBias ? 
this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 ) 
: this.selection.to;
+               offset = this.documentView.getRenderedLineRangeFromOffset( 
offset ).start;
+               if ( !this.keyboard.keys.shift ) {
+                       this.selection.from = this.selection.to = offset;
+                       this.documentView.clearSelection();
+                       this.showCursor();
                } else {
-                       offset = this.selection.to;
-               }
-               
-
-               
-               if ( instruction === 'home' ) {
-                       this.showCursor(
-                               
this.documentView.getRenderedLineRangeFromOffset( offset ).start, false );
-               } else { // end
-                       this.showCursor( 
this.documentView.getRenderedLineRangeFromOffset( offset ).end, true );
-               }
-               if ( this.keyboard.keys.shift ) {
-                       this.drawSelection();
+                       this.selection.to = offset;
+                       this.documentView.drawSelection( this.selection );
                        this.hideCursor();
-               } else {
-                       this.selection.from = this.selection.to;
+               }
+       } else if ( instruction === 'end' ) {
+               var offset = this.cursor.initialBias ? 
this.documentView.getModel().getRelativeContentOffset( this.selection.to, -1 ) 
: this.selection.to;
+               offset = this.documentView.getRenderedLineRangeFromOffset( 
offset ).end;
+               if ( !this.keyboard.keys.shift ) {
+                       this.selection.from = this.selection.to = offset;
                        this.documentView.clearSelection();
+                       this.showCursor();
+               } else {
+                       this.selection.to = offset;
+                       this.documentView.drawSelection( this.selection );
+                       this.hideCursor();
                }
-
        }
 };
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to