r103394 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103393‎ | r103394 | r103395 >
Date:21:59, 16 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Improved support for combination of ctrl/alt/metakey + up/down/left/right - especially for mac vs. windows.
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
@@ -16,6 +16,7 @@
1717 this.model = model;
1818 this.selection = new es.Range();
1919 this.previousSelection = null;
 20+ this.mac = navigator.userAgent.match(/mac/i) ? true : false;
2021
2122 this.model.getDocument().on( 'update', function() {
2223 _this.emit( 'update' );
@@ -65,9 +66,9 @@
6667 keydownTimeout: null,
6768 keys: {
6869 shift: false,
69 - control: false,
70 - command: false,
71 - alt: false
 70+ //control: false,
 71+ //command: false,
 72+ //alt: false
7273 }
7374 };
7475
@@ -251,15 +252,15 @@
252253 this.keyboard.selecting = true;
253254 break;
254255 case 17: // Control
255 - this.keyboard.keys.control = true;
 256+ //this.keyboard.keys.control = true;
256257 break;
257258 case 18: // Alt
258 - this.keyboard.keys.alt = true;
 259+ //this.keyboard.keys.alt = true;
259260 break;
260261 case 91: // Left Command in WebKit
261262 case 93: // Right Command in WebKit
262263 case 224: // Command in FireFox
263 - this.keyboard.keys.command = true;
 264+ //this.keyboard.keys.command = true;
264265 break;
265266 case 36: // Home
266267 this.moveCursor( 'left', 'line' );
@@ -268,36 +269,67 @@
269270 this.moveCursor( 'right', 'line' );
270271 break;
271272 case 37: // Left arrow
272 - if ( this.keyboard.keys.command ) {
273 - this.moveCursor( 'left', 'line' );
274 - } else if ( this.keyboard.keys.control || this.keyboard.keys.alt ) {
275 - this.moveCursor( 'left', 'word' );
 273+ if ( !this.mac ) {
 274+ if ( e.ctrlKey ) {
 275+ this.moveCursor( 'left', 'word' );
 276+ } else {
 277+ this.moveCursor( 'left', 'char' );
 278+ }
276279 } else {
277 - this.moveCursor( 'left', 'char' );
 280+ if ( e.metaKey || e.ctrlKey ) {
 281+ this.moveCursor( 'left', 'line' );
 282+ } else if ( e.altKey ) {
 283+ this.moveCursor( 'left', 'word' );
 284+ } else {
 285+ this.moveCursor( 'left', 'char' );
 286+ }
278287 }
279288 break;
280289 case 38: // Up arrow
281 - if ( this.keyboard.keys.control || this.keyboard.keys.alt ) {
282 - this.moveCursor( 'up', 'unit' );
 290+ if ( !this.mac ) {
 291+ if ( e.ctrlKey ) {
 292+ this.moveCursor( 'up', 'unit' );
 293+ } else {
 294+ this.moveCursor( 'up', 'char' );
 295+ }
283296 } else {
284 - this.moveCursor( 'up', 'char' );
 297+ if ( e.altKey ) {
 298+ this.moveCursor( 'up', 'unit' );
 299+ } else {
 300+ this.moveCursor( 'up', 'char' );
 301+ }
285302 }
286 -
287303 break;
288304 case 39: // Right arrow
289 - if ( this.keyboard.keys.command ) {
290 - this.moveCursor( 'right', 'line' );
291 - } else if ( this.keyboard.keys.control || this.keyboard.keys.alt ) {
292 - this.moveCursor( 'right', 'word' );
 305+ if ( !this.mac ) {
 306+ if ( e.ctrlKey ) {
 307+ this.moveCursor( 'right', 'word' );
 308+ } else {
 309+ this.moveCursor( 'right', 'char' );
 310+ }
293311 } else {
294 - this.moveCursor( 'right', 'char' );
 312+ if ( e.metaKey || e.ctrlKey ) {
 313+ this.moveCursor( 'right', 'line' );
 314+ } else if ( e.altKey ) {
 315+ this.moveCursor( 'right', 'word' );
 316+ } else {
 317+ this.moveCursor( 'right', 'char' );
 318+ }
295319 }
296320 break;
297321 case 40: // Down arrow
298 - if ( this.keyboard.keys.control || this.keyboard.keys.alt ) {
299 - this.moveCursor( 'down', 'unit' );
 322+ if ( !this.mac ) {
 323+ if ( e.ctrlKey ) {
 324+ this.moveCursor( 'down', 'unit' );
 325+ } else {
 326+ this.moveCursor( 'down', 'char' );
 327+ }
300328 } else {
301 - this.moveCursor( 'down', 'char' );
 329+ if ( e.altKey ) {
 330+ this.moveCursor( 'down', 'unit' );
 331+ } else {
 332+ this.moveCursor( 'down', 'char' );
 333+ }
302334 }
303335 break;
304336 case 8: // Backspace
@@ -347,15 +379,15 @@
348380 }
349381 break;
350382 case 17: // Control
351 - this.keyboard.keys.control = false;
 383+ //this.keyboard.keys.control = false;
352384 break;
353385 case 18: // Alt
354 - this.keyboard.keys.alt = false;
 386+ //this.keyboard.keys.alt = false;
355387 break;
356388 case 91: // Left Command in WebKit
357389 case 93: // Right Command in WebKit
358390 case 224: // Command in FireFox
359 - this.keyboard.keys.command = false;
 391+ //this.keyboard.keys.command = false;
360392 break;
361393 default:
362394 break;

Status & tagging log