r99216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99215‎ | r99216 | r99217 >
Date:16:21, 7 October 2011
Author:inez
Status:deferred
Tags:
Comment:
More support for cursor and selection drawing
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -33,19 +33,18 @@
3434 'alt': false
3535 }
3636 };
37 -
38 - /*
39 - this.selecting = false;
40 - this.from = this.to = 0;
41 - */
42 -
 37+ this.selection = {
 38+ 'from': 0,
 39+ 'to': 0
 40+ };
 41+
4342 // Cursor
4443 this.blinkInterval = null;
4544 this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ );
4645
4746 // References for use in closures
4847 var surfaceView = this,
49 - $document = $(document);
 48+ $document = $( document );
5049
5150 // MouseDown on surface
5251 this.$.bind( {
@@ -75,7 +74,7 @@
7675 });
7776 },
7877 'blur': function( e ) {
79 - $document.unbind('.editSurface');
 78+ $document.unbind( '.editSurface' );
8079 surfaceView.hideCursor();
8180 },
8281 'cut': function( e ) {
@@ -103,56 +102,6 @@
104103 this.documentView.renderContent();
105104 };
106105
107 -/**
108 - * Shows the cursor in a new position.
109 - *
110 - * @method
111 - * @param position {Position} Position to show the cursor at
112 - * @param offset {Position} Offset to be added to position
113 - */
114 -es.SurfaceView.prototype.showCursor = function( position, offset ) {
115 -
116 - // TODO: test/reimplement
117 -
118 - if ( position ) {
119 - if ( $.isPlainObject( offset ) ) {
120 - position.left += offset.left;
121 - position.top += offset.top;
122 - position.bottom += offset.top;
123 - }
124 - this.$cursor.css( {
125 - 'left': position.left,
126 - 'top': position.top,
127 - 'height': position.bottom - position.top
128 - } ).show();
129 - } else {
130 - this.$cursor.show();
131 - }
132 -
133 - if ( this.blinkInterval ) {
134 - clearInterval( this.blinkInterval );
135 - }
136 - var $cursor = this.$cursor;
137 - this.blinkInterval = setInterval( function() {
138 - $cursor.$.css( 'display' ) === 'block' ? $cursor.$.hide() : $cursor.$.show();
139 - }, 500 );
140 -};
141 -
142 -/**
143 - * Hides the cursor.
144 - *
145 - * @method
146 - */
147 -es.SurfaceView.prototype.hideCursor = function() {
148 -
149 - // TODO: test/reimplement
150 -
151 - if( this.blinkInterval ) {
152 - clearInterval( this.blinkInterval );
153 - }
154 - this.$cursor.hide();
155 -};
156 -
157106 es.SurfaceView.prototype.onKeyDown = function( e ) {
158107 switch ( e.keyCode ) {
159108 case 16: // Shift
@@ -216,37 +165,43 @@
217166 var contentOffset = this.documentView.getOffsetFromEvent( e ),
218167 position = this.documentView.getRenderedPosition( contentOffset );
219168
220 - if ( position !== null ) {
 169+ if ( e.button === 0 ) {
 170+ if ( this.keyboard.keys.shift ) {
 171+ this.selection.to = contentOffset;
 172+ } else {
 173+ this.selection.from = this.selection.to = contentOffset;
 174+ }
 175+
221176 this.showCursor( position );
 177+ this.mouse.selecting = true;
 178+
 179+ this.documentView.drawSelection( new es.Range( this.selection.from, this.selection.to ) );
222180 }
223181
224 - /*
225 - this.from = contentOffset;
226 - this.selecting = true;
227 -
228182 if ( !this.$input.is(':focus') ) {
229183 this.$input.focus().select();
230184 }
231 - */
232185
233186 return false;
234187 };
235188
236189 es.SurfaceView.prototype.onMouseMove = function( e ) {
237 - /*
238 - if (this.selecting ) {
239 - var contentOffset = this.documentView.getOffsetFromEvent( e );
240 -
241 - this.to = contentOffset;
242 - this.documentView.drawSelection( new es.Range( this.from, this.to ) );
 190+ if ( e.button === 0 && this.mouse.selecting ) {
 191+ this.hideCursor();
 192+ this.selection.to = this.documentView.getOffsetFromEvent( e );
 193+ if ( !this.drawSelection() ) {
 194+ this.showCursor();
 195+ }
243196 }
244 - */
245 - // TODO: Respond to mouse move event, updating selection while painting
246197 };
247198
248199 es.SurfaceView.prototype.onMouseUp = function( e ) {
249 - this.selecting = false;
250 - // TODO: Respond to mouse up event, possibly ending selection painting
 200+ if ( e.button === 0 && this.selection.to ) {
 201+ if ( this.drawSelection() ) {
 202+ this.hideCursor();
 203+ }
 204+ }
 205+ this.mouse.selecting = false;
251206 };
252207
253208 es.SurfaceView.prototype.onCut = function( e ) {
@@ -277,6 +232,13 @@
278233 // TODO: Set the value of this.$input
279234 };
280235
 236+/**
 237+ * Shows the cursor in a new position.
 238+ *
 239+ * @method
 240+ * @param position {Position} Position to show the cursor at
 241+ * @param offset {Position} Offset to be added to position
 242+ */
281243 es.SurfaceView.prototype.showCursor = function( position ) {
282244 if ( position ) {
283245 this.$cursor.css( {
@@ -297,9 +259,23 @@
298260 }, 500, this );
299261 };
300262
 263+/**
 264+ * Hides the cursor.
 265+ *
 266+ * @method
 267+ */
301268 es.SurfaceView.prototype.hideCursor = function( position ) {
302269 if( this.blinkInterval ) {
303270 clearInterval( this.blinkInterval );
304271 }
305272 this.$cursor.hide();
 273+};
 274+
 275+es.SurfaceView.prototype.drawSelection = function() {
 276+ if ( this.selection.from !== this.selection.to ) {
 277+ this.documentView.drawSelection( new es.Range( this.selection.from, this.selection.to ) );
 278+ return true;
 279+ } else {
 280+ return false;
 281+ }
306282 };
\ No newline at end of file

Status & tagging log