From 7bf8cb11db08c61417a4d72b95c2905a4869cf67 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 29 Feb 2016 11:53:05 +0000 Subject: Key bindings; small tweaks... - simplify pass key condition - don't keep key-parsing Regexp in memory - we should reset the key state when the pass keys change --- background_scripts/commands.coffee | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index a36b0c7e..25acdc03 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -101,17 +101,16 @@ Commands = @keyToCommandRegistry = {} @mapKeyToCommand { key, command } for own key, command of defaultKeyMappings - # Keys are either literal characters, or "named" - for example (alt+b), (left arrow) or - # 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})>)(.*)$/ - generateKeyStateMapping: -> + # Keys are either literal characters, or "named" - for example (alt+b), (left arrow) or + # 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})>)(.*)$/ keyStateMapping = {} for own keys, registryEntry of @keyToCommandRegistry currentMapping = keyStateMapping while 0 < keys.length - [key, keys] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]] + [key, keys] = if 0 == keys.search namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]] if currentMapping[key]?.command break # Do not overwrite existing command bindings, they take priority. else if 0 < keys.length -- cgit v1.2.3