From b0d2f3bfbc36232c235f913131c78a5bb76b59c3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 15:35:10 +0000 Subject: Key bindings; and yet more minor tweaks. --- background_scripts/commands.coffee | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'background_scripts/commands.coffee') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 50e5d624..46869451 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -1,13 +1,13 @@ Commands = - init: (customKeyMappings) -> + init: () -> for own command, description of commandDescriptions @addCommand(command, description[0], description[1]) - @loadKeyMappings customKeyMappings + @loadKeyMappings Settings.get "keyMappings" Settings.postUpdateHooks["keyMappings"] = @loadKeyMappings.bind this - loadKeyMappings: (value) -> + loadKeyMappings: (customKeyMappings) -> @clearKeyMappingsAndSetDefaults() - @parseCustomKeyMappings value + @parseCustomKeyMappings customKeyMappings @generateKeyStateMapping() availableCommands: {} @@ -107,19 +107,18 @@ Commands = namedKeyRegex: /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/ generateKeyStateMapping: -> - keyMapping = {} + keyStateMapping = {} for own keys, registryEntry of @keyToCommandRegistry - currentMapping = keyMapping + currentMapping = keyStateMapping while 0 < keys.length - [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]] - if 0 < rest.length - # Do not overwrite existing command bindings, they take priority. - break if (currentMapping[key] ?= {}).command - currentMapping = currentMapping[key] + [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 + currentMapping = (currentMapping[key] ?= {}) else currentMapping[key] = registryEntry - keys = rest - chrome.storage.local.set normalModeKeyStateMapping: keyMapping + chrome.storage.local.set normalModeKeyStateMapping: keyStateMapping # An ordered listing of all available commands, grouped by type. This is the order they will # be shown in the help page. @@ -397,7 +396,7 @@ commandDescriptions = "Marks.activateCreateMode": ["Create a new mark", { noRepeat: true }] "Marks.activateGotoMode": ["Go to a mark", { noRepeat: true }] -Commands.init Settings.get "keyMappings" +Commands.init() root = exports ? window root.Commands = Commands -- cgit v1.2.3