From 8893e55daec12693197e4550a75f28885f47760f Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 29 May 2010 16:09:17 +0100 Subject: Document named key functions (per philc) --- background_page.html | 4 +++- commands.js | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/background_page.html b/background_page.html index 9e43fecd..0f923869 100644 --- a/background_page.html +++ b/background_page.html @@ -15,7 +15,9 @@ var validFirstKeys = {}; var singleKeyCommands = []; - var namedKeyRegex = /^(<[amc-].|(?:[amc]-)?[a-z]{2,5}>)(.*)$/; + // Keys are either literal characters, or "named" - for example (alt+b), (the left arrow) or + // This regular expression captures two groups, the first is a named key, the second is the remainder of the string. + var namedKeyRegex = /^(<[amc-].|(?:[amc]-)?[a-z0-9]{2,5}>)(.*)$/; var defaultSettings = { scrollStepSize: 60, diff --git a/commands.js b/commands.js index 8e4922f3..de6ce701 100644 --- a/commands.js +++ b/commands.js @@ -23,9 +23,20 @@ function mapKeyToCommand(key, command) { function unmapKey(key) { delete keyToCommandRegistry[key]; } +/* Lower-case the appropriate portions of named keys. + * + * A key name is one of three forms exemplified by or + * (prefixed normal key, named key, or prefixed named key). Internally, for + * simplicity, we would like prefixes and key names to be lowercase, though + * humans may prefer other forms or . + * On the other hand, and are different named keys - for one of + * them you have to press "shift" as well. + */ function normalizeKey(key) { - return key.replace(/<[amc]-/i, function(m){return m.toLowerCase();}) - .replace(/<([acm]-)?([a-zA-Z0-9]+)>/, function(m, p, k){return "<" + (p ? p : "") + k.toLowerCase() + ">";}); + return key.replace(/<[acm]-/ig, function(match){ return match.toLowerCase(); }) + .replace(/<([acm]-)?([a-zA-Z0-9]{2,5})>/g, function(match, optionalPrefix, keyName){ + return "<" + ( optionalPrefix ? optionalPrefix : "") + keyName.toLowerCase() + ">"; + }); } function parseCustomKeyMappings(customKeyMappings) { -- cgit v1.2.3