diff options
| author | Phil Crosby | 2009-12-31 13:58:00 -0500 | 
|---|---|---|
| committer | Phil Crosby | 2009-12-31 13:58:00 -0500 | 
| commit | 4400b33be71215a26024b29e9f66143dc9a55df9 (patch) | |
| tree | 35038e307d7d15af48fd09e36c5ebc2d80aa611b /vimiumFrontend.js | |
| parent | d4c6154df8cdfd7fbe274235318959cd196600af (diff) | |
| download | vimium-4400b33be71215a26024b29e9f66143dc9a55df9.tar.bz2 | |
Implement a workaround to correctly translate some keystrokes into characters on Windows. Fixes #40.
This fix is required to work around https://bugs.webkit.org/show_bug.cgi?id=19906
Diffstat (limited to 'vimiumFrontend.js')
| -rw-r--r-- | vimiumFrontend.js | 27 | 
1 files changed, 26 insertions, 1 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index eb265df8..9f64f1c6 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -18,12 +18,32 @@ var settingPort;  var saveZoomLevelPort;  // Users can disable Vimium on URL patterns via the settings page.  var isEnabledForUrl = true; +// The user's operating system.  var platform;  var currentCompletionKeys;  // TODO(philc): This should be pulled from the extension's storage when the page loads.  var currentZoomLevel = 100; +// This is a mapping of the incorrect keyIdentifiers generated by Webkit on Windows during keydown events to +// the correct identifiers, which are correctly generated on Mac. We require this mapping to properly handle +// these keys on Windows. See https://bugs.webkit.org/show_bug.cgi?id=19906 for more details. +// TODO(philc): Currently we cannot distinguish between e.g. ",<"; we'll need to look at the keyboard event's +// shift key to do so on Windows. +var keyIdentifierCorrectionMap = { +  "U+00C0": "U+0060", // `~ +  "U+00BD": "U+002D", // -_ +  "U+00BB": "U+003D", // =+ +  "U+00DB": "U+005B", // [{ +  "U+00DD": "U+005D", // ]} +  "U+00DC": "U+005C", // \| +  "U+00BA": "U+003B", // ;: +  "U+00DE": "U+0027", // '" +  "U+00BC": "U+002C", // ,< +  "U+00BE": "U+002E", // .> +  "U+00BF": "U+002F"  // /? +}; +  function getSetting(key) {    if (!settingPort)      settingPort = chrome.extension.connect({ name: "getSetting" }); @@ -215,7 +235,12 @@ function onKeydown(event) {    // Ignore modifier keys by themselves.    if (event.keyCode > 31) { -    unicodeKeyInHex = "0x" + event.keyIdentifier.substring(2); +    var keyIdentifier = event.keyIdentifier; +    // On Windows, the keyIdentifiers for non-letter keys are incorrect. See +    // https://bugs.webkit.org/show_bug.cgi?id=19906 for more details. +    if (platform == "Windows") +      keyIdentifier = keyIdentifierCorrectionMap[keyIdentifier] || keyIdentifier; +    unicodeKeyInHex = "0x" + keyIdentifier.substring(2);      keyChar = String.fromCharCode(parseInt(unicodeKeyInHex)).toLowerCase();      // Enter insert mode when the user enables the native find interface.  | 
