Skip to content

Commit

Permalink
Properly differentiate between special keys and normal keys in key ha…
Browse files Browse the repository at this point in the history
…ndlers.
  • Loading branch information
nickjs committed Jun 17, 2010
1 parent 96fc34c commit f09193c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions AppKit/Platform/DOM/CPPlatformWindow+DOM.j
Expand Up @@ -640,7 +640,15 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
else
_keyCode = aDOMEvent.keyCode;

var characters = KeyCodesToFunctionUnicodeMap[_keyCode] || String.fromCharCode(_keyCode).toLowerCase();
var characters;

// Is this a special key?
if (aDOMEvent.which === 0 || aDOMEvent.charCode === 0)
characters = KeyCodesToFunctionUnicodeMap[_keyCode];

if (!characters)
characters = String.fromCharCode(_keyCode).toLowerCase();

overrideCharacters = (modifierFlags & CPShiftKeyMask || _capsLockActive) ? characters.toUpperCase() : characters;

// check for caps lock state
Expand Down Expand Up @@ -713,16 +721,23 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
_lastKey = keyCode;
_charCodes[keyCode] = charCode;

var characters = overrideCharacters || KeyCodesToFunctionUnicodeMap[charCode] || String.fromCharCode(charCode),
charactersIgnoringModifiers = characters.toLowerCase();
var characters = overrideCharacters;
// Is this a special key?
if (!characters && (aDOMEvent.which === 0 || aDOMEvent.charCode === 0))
characters = KeyCodesToFunctionUnicodeMap[charCode];

if (!characters)
characters = String.fromCharCode(charCode);

charactersIgnoringModifiers = characters.toLowerCase(); // FIXME: This isn't correct. It SHOULD include Shift.

// Safari won't send proper capitalization during cmd-key events
if (!overrideCharacters && (modifierFlags & CPCommandKeyMask) && ((modifierFlags & CPShiftKeyMask) || _capsLockActive))
characters = characters.toUpperCase();

event = [CPEvent keyEventWithType:CPKeyDown location:location modifierFlags:modifierFlags
timestamp:timestamp windowNumber:windowNumber context:nil
characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:isARepeat keyCode:keyCode];
characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:isARepeat keyCode:charCode];

if (isNativePasteEvent)
{
Expand Down

0 comments on commit f09193c

Please sign in to comment.