From 5ecdaafadfa5f0413415ea7eda0ffc6550bc35d1 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Tue, 1 Jul 2025 20:23:29 +0200 Subject: [PATCH] fixed: arrow keys did not work --- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 7c8ad47f5..2ecd0c48d 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -736,8 +736,9 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio var characters; // Handle key codes for which String.fromCharCode won't work. - // Refs #1036: In Internet Explorer, both 'which' and 'charCode' are undefined for special keys. - if (aDOMEvent.which === 0 || aDOMEvent.charCode === 0 || (aDOMEvent.which === undefined && aDOMEvent.charCode === undefined)) + // This condition is for identifying non-printing keys based on the keydown event. + // We've replaced the deprecated '.which' with a direct check on charCode. + if (!aDOMEvent.charCode) characters = KeyCodesToUnicodeMap[_keyCode]; // The problem with keyCode is that this property refers to keys on the keyboard and not to characters @@ -802,11 +803,19 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio _charCodes[keyCode] = charCode; var characters = overrideCharacters; - // Is this a special key? - if (!characters && (aDOMEvent.which === 0 || aDOMEvent.charCode === 0)) - characters = KeyCodesToUnicodeMap[charCode]; - if (!characters) + // This condition is met for non-printing keys (like Enter, Tab, arrows) that fall through + // from the 'keydown' case, as their charCode is 0 in the keydown DOM event. + if (!characters && (!aDOMEvent.charCode || aDOMEvent.charCode === 0)) + characters = KeyCodesToUnicodeMap[charCode]; // Note: for fall-through, charCode is actually the keyCode from the keydown event. + + // For modern browsers, event.key is the most reliable way to get the actual character, + // especially for international keyboards. We only use it for single-character keys. + if (!characters && aDOMEvent.key && aDOMEvent.key.length === 1) + characters = aDOMEvent.key; + + // Fallback for older browsers that support charCode but not key. + if (!characters && charCode > 0) characters = String.fromCharCode(charCode); charactersIgnoringModifiers = characters.toLowerCase(); // FIXME: This isn't correct. It SHOULD include Shift.