From 8f7ce742de56ea15395b8397daf9e8db9f8a8322 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 21 Jun 2012 11:07:18 -0700 Subject: [PATCH] Aggressive keyboard shortcut fix for all browsers and platforms Change-Id: Ic9e6359a06752861a05526dba090b08ccd39b83f --- modules/ve/ce/ve.ce.Surface.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index ee164ec443..495551d168 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -196,9 +196,9 @@ ve.ce.Surface.prototype.onKeyDown = function( e ) { break; // B case 66: - if ( e.metaKey ) { - e.preventDefault(); + if ( ve.ce.Surface.isShortcutKey( e ) ) { // Ctrl+B / Cmd+B, annotate with bold + e.preventDefault(); var annotations = this.documentView.model.getAnnotationsFromRange( this.model.getSelection() ), annotation = {"type":"textStyle/bold"}; @@ -207,13 +207,13 @@ ve.ce.Surface.prototype.onKeyDown = function( e ) { break; // I case 73: - if ( e.metaKey ) { + if ( ve.ce.Surface.isShortcutKey( e ) ) { // Ctrl+I / Cmd+I, annotate with italic + e.preventDefault(); var annotations = this.documentView.model.getAnnotationsFromRange( this.model.getSelection() ), annotation = {"type":"textStyle/italic"}; this.model.annotate( annotations[ve.getHash(annotation)] ? 'clear' : 'set', annotation ); - e.preventDefault(); } break; default: @@ -312,7 +312,7 @@ ve.ce.Surface.prototype.onPaste = function( e ) { ve.ce.Surface.prototype.onKeyPress = function( e ) { ve.log('onKeyPress'); - if (e.metaKey) { + if ( ve.ce.Surface.isShortcutKey( e ) ) { return; } @@ -1036,6 +1036,14 @@ ve.ce.Surface.prototype.getSelectionRect = function() { }; }; +/* Tests if the modifier key for keyboard shortcuts is pressed. */ +ve.ce.Surface.isShortcutKey = function( e ) { + if ( e.ctrlKey || e.metaKey ) { + return true; + } + return false; +}; + ve.ce.Surface.prototype.getModel = function() { return this.model; };