diff options
| author | Stephen Blott | 2016-09-17 11:05:22 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-09-17 11:05:22 +0100 |
| commit | c9369c3e34490afdfa39c6f9520ee24367c0eacd (patch) | |
| tree | 1037e5145571787cc7f382393b2229538b0644f3 | |
| parent | 0006776fecdd5eb02da8973ae6856824c090c82e (diff) | |
| parent | 9f0ec8cd06903fc25d65b0b82cf8e5fb4e9f5c7a (diff) | |
| download | vimium-c9369c3e34490afdfa39c6f9520ee24367c0eacd.tar.bz2 | |
Merge branch 'gdh1995-backspace-as-go-back'
| -rw-r--r-- | background_scripts/commands.coffee | 4 | ||||
| -rw-r--r-- | lib/keyboard_utils.coffee | 22 |
2 files changed, 16 insertions, 10 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index c334cf9d..f865131d 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -41,7 +41,7 @@ Commands = # them you have to press "shift" as well. normalizeKey: (key) -> key.replace(/<[acm]-/ig, (match) -> match.toLowerCase()) - .replace(/<([acm]-)?([a-zA-Z0-9]{2,5})>/g, (match, optionalPrefix, keyName) -> + .replace(/<([acm]-)?([a-zA-Z0-9]{2,})>/g, (match, optionalPrefix, keyName) -> "<" + (if optionalPrefix then optionalPrefix else "") + keyName.toLowerCase() + ">") parseCustomKeyMappings: (customKeyMappings) -> @@ -97,7 +97,7 @@ Commands = # Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (left arrow) or <f12> # This regular expression captures two groups: the first is a named key, the second is the remainder of # the string. - namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/ + namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,})>)(.*)$/ keyStateMapping = {} for own keys, registryEntry of @keyToCommandRegistry currentMapping = keyStateMapping diff --git a/lib/keyboard_utils.coffee b/lib/keyboard_utils.coffee index 9c694826..dabf864d 100644 --- a/lib/keyboard_utils.coffee +++ b/lib/keyboard_utils.coffee @@ -4,7 +4,7 @@ KeyboardUtils = f12: 123, tab: 9, downArrow: 40, upArrow: 38 } keyNames: - { 37: "left", 38: "up", 39: "right", 40: "down", 32: "space" } + { 37: "left", 38: "up", 39: "right", 40: "down", 32: "space", 8: "backspace" } # 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 @@ -53,15 +53,21 @@ KeyboardUtils = "" getKeyCharUsingKeyIdentifier: (event) -> - # Not a letter - if (event.keyIdentifier.slice(0, 2) != "U+") - return @keyNames[event.keyCode] if (@keyNames[event.keyCode]) - # F-key - if (event.keyCode >= @keyCodes.f1 && event.keyCode <= @keyCodes.f12) - return "f" + (1 + event.keyCode - keyCodes.f1) - return "" + # Handle named keys. + keyCode = event.keyCode + if keyCode + if keyCode of @keyNames + return @keyNames[keyCode] + # Function keys. + if @keyCodes.f1 <= keyCode <= @keyCodes.f12 + return "f" + (1 + keyCode - keyCodes.f1) keyIdentifier = event.keyIdentifier + + # Not a letter. + if not keyIdentifier.startsWith "U+" + return "" + # 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" || @platform == "Linux") && @keyIdentifierCorrectionMap[keyIdentifier]) |
