r93305 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93304‎ | r93305 | r93306 >
Date:20:04, 27 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved key states to this.keyboard.keys, added click -> shift+click to select functionality.
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -22,7 +22,13 @@
2323 };
2424 this.keyboard = {
2525 'selecting': false,
26 - 'keydownTimeout': null
 26+ 'keydownTimeout': null,
 27+ 'keys': {
 28+ 'shift': false,
 29+ 'control': false,
 30+ 'command': false,
 31+ 'alt': false
 32+ }
2733 };
2834
2935 // MouseDown on surface
@@ -122,7 +128,7 @@
123129 es.Surface.prototype.onKeyDown = function( e ) {
124130 switch ( e.keyCode ) {
125131 case 16: // Shift
126 - this.shiftDown = true;
 132+ this.keyboard.keys.shift = true;
127133 if ( !this.keyboard.selecting ) {
128134 this.keyboard.selecting = true;
129135 if ( !this.selection.to ) {
@@ -132,18 +138,18 @@
133139 }
134140 break;
135141 case 17: // Control
136 - this.ctrlDown = true;
 142+ this.keyboard.keys.control = true;
137143 break;
138144 case 18: // Alt
139 - this.altDown = true;
 145+ this.keyboard.keys.alt = true;
140146 break;
141147 case 91: // Command
142 - this.commandDown = true;
 148+ this.keyboard.keys.command = true;
143149 break;
144150 case 37: // Left arrow
145151 this.initialHorizontalCursorPosition = null;
146152 this.moveCursorLeft();
147 - if ( this.shiftDown && this.keyboard.selecting ) {
 153+ if ( this.keyboard.keys.shift && this.keyboard.selecting ) {
148154 this.selection.to = this.location;
149155 } else {
150156 this.selection = new es.Selection();
@@ -152,7 +158,7 @@
153159 break;
154160 case 38: // Up arrow
155161 this.moveCursorUp();
156 - if ( this.shiftDown && this.keyboard.selecting ) {
 162+ if ( this.keyboard.keys.shift && this.keyboard.selecting ) {
157163 this.selection.to = this.location;
158164 } else {
159165 this.selection = new es.Selection();
@@ -162,7 +168,7 @@
163169 case 39: // Right arrow
164170 this.initialHorizontalCursorPosition = null;
165171 this.moveCursorRight();
166 - if ( this.shiftDown && this.keyboard.selecting ) {
 172+ if ( this.keyboard.keys.shift && this.keyboard.selecting ) {
167173 this.selection.to = this.location;
168174 } else {
169175 this.selection = new es.Selection();
@@ -171,7 +177,7 @@
172178 break;
173179 case 40: // Down arrow
174180 this.moveCursorDown();
175 - if ( this.shiftDown && this.keyboard.selecting ) {
 181+ if ( this.keyboard.keys.shift && this.keyboard.selecting ) {
176182 this.selection.to = this.location;
177183 } else {
178184 this.selection = new es.Selection();
@@ -186,7 +192,7 @@
187193 this.handleDelete();
188194 break;
189195 default:
190 - if ( this.ctrlDown || this.altDown || this.commandDown ) {
 196+ if ( this.keyboard.keys.control || this.keyboard.keys.alt || this.keyboard.keys.command ) {
191197 break;
192198 }
193199 this.initialHorizontalCursorPosition = null;
@@ -242,21 +248,21 @@
243249 es.Surface.prototype.onKeyUp = function( e ) {
244250 switch ( e.keyCode ) {
245251 case 16: // Shift
246 - this.shiftDown = false;
 252+ this.keyboard.keys.shift = false;
247253 if ( this.keyboard.selecting ) {
248254 this.keyboard.selecting = false;
249255 }
250256 break;
251257 case 17: // Control
252 - this.ctrlDown = false;
 258+ this.keyboard.keys.control = false;
253259 break;
254260 case 18: // Alt
255 - this.altDown = false;
 261+ this.keyboard.keys.alt = false;
256262 break;
257263 case 91: // Command
258 - this.commandDown = false;
 264+ this.keyboard.keys.command = false;
259265 break;
260 - default:
 266+ default:
261267 break;
262268 }
263269 return true;
@@ -317,8 +323,12 @@
318324 this.location = this.getLocationFromEvent( e );
319325 switch ( this.mouse.clicks ) {
320326 case 1:
321 - // Clear selection and move cursor to nearest offset
322 - this.selection = new es.Selection( this.location );
 327+ if ( this.keyboard.keys.shift ) {
 328+ this.selection = new es.Selection( this.selection.from, this.location );
 329+ } else {
 330+ // Clear selection and move cursor to nearest offset
 331+ this.selection = new es.Selection( this.location );
 332+ }
323333 var cursorPosition = this.location.block.getPosition( this.location.offset );
324334 this.cursor.show( cursorPosition, this.location.block.$.offset() );
325335 this.$input.css( 'top', cursorPosition.top );

Status & tagging log