Skip to content

Commit

Permalink
Merge pull request sproutcore#538 from oruen/keypress_with_equal_keyc…
Browse files Browse the repository at this point in the history
…ode_and_charcode

Keypress with equal keycode and charcode, refs sproutcore#83
  • Loading branch information
Colin Campbell committed Sep 27, 2011
2 parents 328be9c + 778ece0 commit 8b45bcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frameworks/core_foundation/system/event.js
Expand Up @@ -920,7 +920,8 @@ SC.Event.prototype = {
var code=this.keyCode, ret=null, key=null, modifiers='', lowercase ;

// handle function keys.
if (code) {
// WebKit browsers have equal values for keyCode and charCode on keypress event
if (code && code !== this.charCode) {
ret = SC.FUNCTION_KEYS[code] ;
if (!ret && (this.altKey || this.ctrlKey || this.metaKey)) {
ret = SC.PRINTABLE_KEYS[code];
Expand Down
22 changes: 22 additions & 0 deletions frameworks/core_foundation/tests/system/event.js
@@ -0,0 +1,22 @@
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================

// // ========================================================================
// SC.Event Tests
// ========================================================================
(function () {
module("SC.Event");

// WebKit browsers have equal values for keyCode and charCode on keypress event
test("commandCodes() : should handle equal keyCode and charCode on keypress", function () {
// 115 is alose keyCode for F4 button
var codes = new SC.Event({ type: 'keypress', keyCode: 115, charCode: 115 }).commandCodes();
equals(codes[0], null, 'command');
equals(codes[1], 's', 'char');
});
})();

0 comments on commit 8b45bcf

Please sign in to comment.