From 34b1fb0f4e2ce1696c17e703d0bc43463355d6ba Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 14:20:12 +0000 Subject: Key bindings; initial partially-functioning version. --- background_scripts/commands.coffee | 20 ++++++++++++++++++++ background_scripts/main.coffee | 1 + 2 files changed, 21 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index ab9992b3..a1002929 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -94,6 +94,25 @@ 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})>)(.*)$/ + + generateKeyStateStructure: -> + keyMapping = {} + for own keys, registryEntry of @keyToCommandRegistry + currentMapping = keyMapping + while 0 < keys.length + [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys.slice(1)] + if 0 < rest.length + currentMapping[key] ?= {} + currentMapping = currentMapping[key] + else + currentMapping[key] = registryEntry + keys = rest + chrome.storage.local.set normalModeKeyStateMapping: keyMapping + # An ordered listing of all available commands, grouped by type. This is the order they will # be shown in the help page. commandGroups: @@ -375,6 +394,7 @@ Commands.init() Settings.postUpdateHooks["keyMappings"] = (value) -> Commands.clearKeyMappingsAndSetDefaults() Commands.parseCustomKeyMappings value + Commands.generateKeyStateStructure() refreshCompletionKeysAfterMappingSave() root = exports ? window diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 7c970866..1838eb95 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -629,6 +629,7 @@ Commands.clearKeyMappingsAndSetDefaults() if Settings.has("keyMappings") Commands.parseCustomKeyMappings(Settings.get("keyMappings")) +Commands.generateKeyStateStructure() populateValidFirstKeys() populateSingleKeyCommands() -- cgit v1.2.3 From 3f63ceb19046157692eac9e9a13486af7e50a57e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 14:44:34 +0000 Subject: Key bindings; partially functioning w/ backgound commands. --- background_scripts/main.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 1838eb95..41b9bf8a 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -519,6 +519,14 @@ checkKeyQueue = (keysToCheck, tabId, frameId) -> newKeyQueue +runBackgroundCommand = ({frameId, registryEntry, count}) -> + if registryEntry.passCountToFunction + BackgroundCommands[registryEntry.command] count, frameId + else if registryEntry.noRepeat + BackgroundCommands[registryEntry.command] frameId + else + repeatFunction BackgroundCommands[registryEntry.command], count, 0, frameId + # # Message all tabs. Args should be the arguments hash used by the Chrome sendRequest API. # @@ -578,6 +586,7 @@ portHandlers = completions: handleCompletions sendRequestHandlers = + runBackgroundCommand: runBackgroundCommand getCompletionKeys: getCompletionKeysRequest getCurrentTabUrl: getCurrentTabUrl openUrlInNewTab: TabOperations.openUrlInNewTab -- cgit v1.2.3 From d388eddd192d925cda43700d7090ce8d52499df0 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 15:25:28 +0000 Subject: Key bindings; remove legacy code. --- background_scripts/commands.coffee | 1 - background_scripts/main.coffee | 161 +------------------------------------ 2 files changed, 1 insertion(+), 161 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index a1002929..7e02047c 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -395,7 +395,6 @@ Settings.postUpdateHooks["keyMappings"] = (value) -> Commands.clearKeyMappingsAndSetDefaults() Commands.parseCustomKeyMappings value Commands.generateKeyStateStructure() - refreshCompletionKeysAfterMappingSave() root = exports ? window root.Commands = Commands diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 41b9bf8a..1cb00a82 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -19,17 +19,9 @@ chrome.runtime.onInstalled.addListener ({ reason }) -> func tab.id, { file: file, allFrames: contentScripts.all_frames }, checkLastRuntimeError currentVersion = Utils.getCurrentVersion() -keyQueue = "" # Queue of keys typed -validFirstKeys = {} -singleKeyCommands = [] frameIdsForTab = {} root.urlForTab = {} -# 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})>)(.*)$/ - # This is exported for use by "marks.coffee". root.tabLoadedHandlers = {} # tabId -> function() @@ -189,14 +181,6 @@ fetchFileContents = (extensionFileName) -> req.send() req.responseText -# -# Returns the keys that can complete a valid command given the current key queue. -# -getCompletionKeysRequest = (request, keysToCheck = "") -> - name: "refreshCompletionKeys" - completionKeys: generateCompletionKeys(keysToCheck) - validFirstKeys: validFirstKeys - TabOperations = # Opens the url in the current tab. openUrlInCurrentTab: (request, callback = (->)) -> @@ -385,140 +369,6 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> # End action functions -splitKeyIntoFirstAndSecond = (key) -> - if (key.search(namedKeyRegex) == 0) - { first: RegExp.$1, second: RegExp.$2 } - else - { first: key[0], second: key.slice(1) } - -getActualKeyStrokeLength = (key) -> - if (key.search(namedKeyRegex) == 0) - 1 + getActualKeyStrokeLength(RegExp.$2) - else - key.length - -populateValidFirstKeys = -> - for own key of Commands.keyToCommandRegistry - if (getActualKeyStrokeLength(key) == 2) - validFirstKeys[splitKeyIntoFirstAndSecond(key).first] = true - -populateSingleKeyCommands = -> - for own key of Commands.keyToCommandRegistry - if (getActualKeyStrokeLength(key) == 1) - singleKeyCommands.push(key) - -# Invoked by options.coffee. -root.refreshCompletionKeysAfterMappingSave = -> - validFirstKeys = {} - singleKeyCommands = [] - - populateValidFirstKeys() - populateSingleKeyCommands() - - sendRequestToAllTabs(getCompletionKeysRequest()) - -# Generates a list of keys that can complete a valid command given the current key queue or the one passed in -generateCompletionKeys = (keysToCheck) -> - splitHash = splitKeyQueue(keysToCheck || keyQueue) - command = splitHash.command - count = splitHash.count - - completionKeys = singleKeyCommands.slice(0) - - if (getActualKeyStrokeLength(command) == 1) - for own key of Commands.keyToCommandRegistry - splitKey = splitKeyIntoFirstAndSecond(key) - if (splitKey.first == command) - completionKeys.push(splitKey.second) - - completionKeys - -splitKeyQueue = (queue) -> - match = /([1-9][0-9]*)?(.*)/.exec(queue) - count = parseInt(match[1], 10) - command = match[2] - - { count: count, command: command } - -handleKeyDown = (sender) -> (request, port) -> - key = request.keyChar - if (key == "") - logMessage "clearing keyQueue", sender - keyQueue = "" - else - logMessage "checking keyQueue: [#{keyQueue + key}]", sender - keyQueue = checkKeyQueue(keyQueue + key, port.sender.tab.id, request.frameId) - logMessage "new KeyQueue: #{keyQueue}", sender - # Tell the content script whether there are keys in the queue. - # FIXME: There is a race condition here. The behaviour in the content script depends upon whether this message gets - # back there before or after the next keystroke. - # That being said, I suspect there are other similar race conditions here, for example in checkKeyQueue(). - # Steve (23 Aug, 14). - chrome.tabs.sendMessage(port.sender.tab.id, - name: "currentKeyQueue", - keyQueue: keyQueue) - -checkKeyQueue = (keysToCheck, tabId, frameId) -> - refreshedCompletionKeys = false - splitHash = splitKeyQueue(keysToCheck) - command = splitHash.command - count = splitHash.count - - return keysToCheck if command.length == 0 - count = 1 if isNaN(count) - - if (Commands.keyToCommandRegistry[command]) - registryEntry = Commands.keyToCommandRegistry[command] - runCommand = true - count *= registryEntry.options.count ? 1 - - if registryEntry.noRepeat - count = 1 - else if registryEntry.repeatLimit and count > registryEntry.repeatLimit - runCommand = confirm """ - You have asked Vimium to perform #{count} repeats of the command: - #{Commands.availableCommands[registryEntry.command].description} - - Are you sure you want to continue? - """ - - if runCommand - if not registryEntry.isBackgroundCommand - chrome.tabs.sendMessage tabId, - name: "executePageCommand" - command: registryEntry.command - frameId: frameId - count: count - completionKeys: generateCompletionKeys "" - registryEntry: registryEntry - refreshedCompletionKeys = true - else - if registryEntry.passCountToFunction - BackgroundCommands[registryEntry.command](count, frameId) - else if registryEntry.noRepeat - BackgroundCommands[registryEntry.command](frameId) - else - repeatFunction(BackgroundCommands[registryEntry.command], count, 0, frameId) - - newKeyQueue = "" - else if (getActualKeyStrokeLength(command) > 1) - splitKey = splitKeyIntoFirstAndSecond(command) - - # The second key might be a valid command by its self. - if (Commands.keyToCommandRegistry[splitKey.second]) - newKeyQueue = checkKeyQueue(splitKey.second, tabId, frameId) - else - newKeyQueue = (if validFirstKeys[splitKey.second] then splitKey.second else "") - else - newKeyQueue = (if validFirstKeys[command] then count.toString() + command else "") - - # If we haven't sent the completion keys piggybacked on executePageCommand, - # send them by themselves. - unless refreshedCompletionKeys - chrome.tabs.sendMessage(tabId, getCompletionKeysRequest(null, newKeyQueue), null) - - newKeyQueue - runBackgroundCommand = ({frameId, registryEntry, count}) -> if registryEntry.passCountToFunction BackgroundCommands[registryEntry.command] count, frameId @@ -582,12 +432,10 @@ bgLog = (request, sender) -> # Port handler mapping portHandlers = - keyDown: handleKeyDown, completions: handleCompletions sendRequestHandlers = runBackgroundCommand: runBackgroundCommand - getCompletionKeys: getCompletionKeysRequest getCurrentTabUrl: getCurrentTabUrl openUrlInNewTab: TabOperations.openUrlInNewTab openUrlInIncognito: TabOperations.openUrlInIncognito @@ -633,14 +481,7 @@ window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html' # # Begin initialization. # -Commands.clearKeyMappingsAndSetDefaults() - -if Settings.has("keyMappings") - Commands.parseCustomKeyMappings(Settings.get("keyMappings")) - -Commands.generateKeyStateStructure() -populateValidFirstKeys() -populateSingleKeyCommands() +Settings.postUpdateHooks["keyMappings"] Settings.get "keyMappings" # Show notification on upgrade. showUpgradeMessage = -> -- cgit v1.2.3 From 320dfd5419b4a7e676f8690a87b275b305440dc3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 15:45:26 +0000 Subject: Key bindings; more remove legacy code. --- background_scripts/main.coffee | 9 --------- 1 file changed, 9 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 1cb00a82..60c161f9 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -377,15 +377,6 @@ runBackgroundCommand = ({frameId, registryEntry, count}) -> else repeatFunction BackgroundCommands[registryEntry.command], count, 0, frameId -# -# Message all tabs. Args should be the arguments hash used by the Chrome sendRequest API. -# -sendRequestToAllTabs = (args) -> - chrome.windows.getAll({ populate: true }, (windows) -> - for window in windows - for tab in window.tabs - chrome.tabs.sendMessage(tab.id, args, null)) - openOptionsPageInNewTab = -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 })) -- cgit v1.2.3 From 6487c09d98b791b3211679d2f1bf970394a696e6 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 16:05:23 +0000 Subject: Key bindings; rewire vomnibar. --- background_scripts/commands.coffee | 14 +++++++------- background_scripts/main.coffee | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 7e02047c..a62c674e 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -374,13 +374,13 @@ commandDescriptions = moveTabLeft: ["Move tab to the left", { background: true, passCountToFunction: true }] moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true }] - "Vomnibar.activate": ["Open URL, bookmark, or history entry", { noRepeat: true }] - "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { noRepeat: true }] - "Vomnibar.activateTabSelection": ["Search through your open tabs", { noRepeat: true }] - "Vomnibar.activateBookmarks": ["Open a bookmark", { noRepeat: true }] - "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { noRepeat: true }] - "Vomnibar.activateEditUrl": ["Edit the current URL", { noRepeat: true }] - "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { noRepeat: true }] + "Vomnibar.activate": ["Open URL, bookmark, or history entry", { background: true, noRepeat: true }] + "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { background: true, noRepeat: true }] + "Vomnibar.activateTabSelection": ["Search through your open tabs", { background: true, noRepeat: true }] + "Vomnibar.activateBookmarks": ["Open a bookmark", { background: true, noRepeat: true }] + "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { background: true, noRepeat: true }] + "Vomnibar.activateEditUrl": ["Edit the current URL", { background: true, noRepeat: true }] + "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { background: true, noRepeat: true }] nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }] mainFrame: ["Select the tab's main/top frame", { background: true, noRepeat: true }] diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 60c161f9..8d2b4248 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -369,7 +369,16 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> # End action functions -runBackgroundCommand = ({frameId, registryEntry, count}) -> +# Open Vomnibar in tab's main frame. +openVomnibar = (tabId, frameId, registryEntry) -> + chrome.tabs.sendMessage tabId, + name: "openVomnibar" + sourceFrameId: frameId + registryEntry: registryEntry + +runBackgroundCommand = ({frameId, registryEntry, count}, sender) -> + if registryEntry.command.split(".")[0] == "Vomnibar" + openVomnibar sender.tab.id, frameId, registryEntry if registryEntry.passCountToFunction BackgroundCommands[registryEntry.command] count, frameId else if registryEntry.noRepeat -- cgit v1.2.3 From a881ade2023a6e602097b0ae28c515fc3e9c5e8a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 16:40:38 +0000 Subject: Key bindings; rewire vomnibar (fix minor error). --- background_scripts/commands.coffee | 1 + background_scripts/main.coffee | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index a62c674e..a82a6dcb 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -374,6 +374,7 @@ commandDescriptions = moveTabLeft: ["Move tab to the left", { background: true, passCountToFunction: true }] moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true }] + # These are background-page commands because all requests go via the background page. "Vomnibar.activate": ["Open URL, bookmark, or history entry", { background: true, noRepeat: true }] "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { background: true, noRepeat: true }] "Vomnibar.activateTabSelection": ["Search through your open tabs", { background: true, noRepeat: true }] diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 8d2b4248..7975ec6d 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -379,7 +379,7 @@ openVomnibar = (tabId, frameId, registryEntry) -> runBackgroundCommand = ({frameId, registryEntry, count}, sender) -> if registryEntry.command.split(".")[0] == "Vomnibar" openVomnibar sender.tab.id, frameId, registryEntry - if registryEntry.passCountToFunction + else if registryEntry.passCountToFunction BackgroundCommands[registryEntry.command] count, frameId else if registryEntry.noRepeat BackgroundCommands[registryEntry.command] frameId -- cgit v1.2.3 From 18b8db13fa5184e0cc3ac5fd6645620fdb9d5cef Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 27 Feb 2016 17:33:05 +0000 Subject: Key bindings; tweaks and fixes. --- background_scripts/commands.coffee | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index a82a6dcb..2982b861 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -104,10 +104,9 @@ Commands = for own keys, registryEntry of @keyToCommandRegistry currentMapping = keyMapping while 0 < keys.length - [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys.slice(1)] + [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]] if 0 < rest.length - currentMapping[key] ?= {} - currentMapping = currentMapping[key] + currentMapping = currentMapping[key] ?= {} else currentMapping[key] = registryEntry keys = rest -- cgit v1.2.3 From a7136933b3e63ec5a7a50cd1dab9547b51f2d6d9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 08:34:14 +0000 Subject: Key bindings; handle overlapping bindings With: map g something map gg somethingElse The mapping for "g" always takes priority, regardless of the order in which they're encountered in `@keyToCommandRegistry`. --- background_scripts/commands.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 2982b861..10d20753 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -106,7 +106,9 @@ Commands = 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 - currentMapping = currentMapping[key] ?= {} + # Do not overwrite existing command bindings, they take priority. + break if (currentMapping[key] ?= {}).command + currentMapping = currentMapping[key] else currentMapping[key] = registryEntry keys = rest -- cgit v1.2.3 From 5d918f75715cc2c595a77f1e9dc8fe545fabb663 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 08:40:58 +0000 Subject: Key bindings; more tweaks and fixes. - There's no need to keep `@keyToCommandRegistry`; it's regenerated whenever it's needed. --- background_scripts/commands.coffee | 1 + 1 file changed, 1 insertion(+) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 10d20753..9348e3c5 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -113,6 +113,7 @@ Commands = currentMapping[key] = registryEntry keys = rest chrome.storage.local.set normalModeKeyStateMapping: keyMapping + @keyToCommandRegistry = {} # We don't need this any more, so free up the memory. # An ordered listing of all available commands, grouped by type. This is the order they will # be shown in the help page. -- cgit v1.2.3 From 1ae95161b021fc9a64e139485b0dac047a874c0e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 09:44:55 +0000 Subject: Key bindings; simplify Commands initialization. --- background_scripts/commands.coffee | 17 +++++++++-------- background_scripts/main.coffee | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 9348e3c5..de03136e 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -1,7 +1,14 @@ Commands = - init: -> + init: (customKeyMappings) -> for own command, description of commandDescriptions @addCommand(command, description[0], description[1]) + @loadKeyMappings customKeyMappings + Settings.postUpdateHooks["keyMappings"] = @loadKeyMappings.bind this + + loadKeyMappings: (value) -> + @clearKeyMappingsAndSetDefaults() + @parseCustomKeyMappings value + @generateKeyStateStructure() availableCommands: {} keyToCommandRegistry: {} @@ -391,13 +398,7 @@ commandDescriptions = "Marks.activateCreateMode": ["Create a new mark", { noRepeat: true }] "Marks.activateGotoMode": ["Go to a mark", { noRepeat: true }] -Commands.init() - -# Register postUpdateHook for keyMappings setting. -Settings.postUpdateHooks["keyMappings"] = (value) -> - Commands.clearKeyMappingsAndSetDefaults() - Commands.parseCustomKeyMappings value - Commands.generateKeyStateStructure() +Commands.init Settings.get "keyMappings" root = exports ? window root.Commands = Commands diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 7975ec6d..f5bf90a6 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -481,7 +481,6 @@ window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html' # # Begin initialization. # -Settings.postUpdateHooks["keyMappings"] Settings.get "keyMappings" # Show notification on upgrade. showUpgradeMessage = -> -- cgit v1.2.3 From f0c0a07a2dcb7c73f6aa93de166d8fa87e21f305 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 09:56:56 +0000 Subject: Key bindings; reinstate keyToCommandRegistry. ... We need it for the help page. --- background_scripts/commands.coffee | 1 - 1 file changed, 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index de03136e..e32707ce 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -120,7 +120,6 @@ Commands = currentMapping[key] = registryEntry keys = rest chrome.storage.local.set normalModeKeyStateMapping: keyMapping - @keyToCommandRegistry = {} # We don't need this any more, so free up the memory. # An ordered listing of all available commands, grouped by type. This is the order they will # be shown in the help page. -- cgit v1.2.3 From 6e37f605fe45ee5eca03153c35c55c231e703c95 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 11:07:21 +0000 Subject: Key bindings; minor tweaks. --- background_scripts/commands.coffee | 4 ++-- background_scripts/main.coffee | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index e32707ce..50e5d624 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -8,7 +8,7 @@ Commands = loadKeyMappings: (value) -> @clearKeyMappingsAndSetDefaults() @parseCustomKeyMappings value - @generateKeyStateStructure() + @generateKeyStateMapping() availableCommands: {} keyToCommandRegistry: {} @@ -106,7 +106,7 @@ Commands = # string. namedKeyRegex: /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/ - generateKeyStateStructure: -> + generateKeyStateMapping: -> keyMapping = {} for own keys, registryEntry of @keyToCommandRegistry currentMapping = keyMapping diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f5bf90a6..d1ca501d 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -369,16 +369,10 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> # End action functions -# Open Vomnibar in tab's main frame. -openVomnibar = (tabId, frameId, registryEntry) -> - chrome.tabs.sendMessage tabId, - name: "openVomnibar" - sourceFrameId: frameId - registryEntry: registryEntry - runBackgroundCommand = ({frameId, registryEntry, count}, sender) -> if registryEntry.command.split(".")[0] == "Vomnibar" - openVomnibar sender.tab.id, frameId, registryEntry + chrome.tabs.sendMessage sender.tab.id, + name: "openVomnibar", sourceFrameId: frameId, registryEntry: registryEntry else if registryEntry.passCountToFunction BackgroundCommands[registryEntry.command] count, frameId else if registryEntry.noRepeat -- cgit v1.2.3 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') 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 From f2bced459457dcc962d4bafe2fdf2e6245506ee3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 16:07:25 +0000 Subject: Key bindings; tweaks. --- background_scripts/commands.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 46869451..a36b0c7e 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -1,5 +1,5 @@ Commands = - init: () -> + init: -> for own command, description of commandDescriptions @addCommand(command, description[0], description[1]) @loadKeyMappings Settings.get "keyMappings" @@ -115,7 +115,7 @@ Commands = if currentMapping[key]?.command break # Do not overwrite existing command bindings, they take priority. else if 0 < keys.length - currentMapping = (currentMapping[key] ?= {}) + currentMapping = currentMapping[key] ?= {} else currentMapping[key] = registryEntry chrome.storage.local.set normalModeKeyStateMapping: keyStateMapping -- cgit v1.2.3 From e4193e2752ee7132ff16a7ba977857f70df2946b Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 29 Feb 2016 06:31:43 +0000 Subject: Key bindings; tweaks. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index d1ca501d..614b74c0 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -370,7 +370,7 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> # End action functions runBackgroundCommand = ({frameId, registryEntry, count}, sender) -> - if registryEntry.command.split(".")[0] == "Vomnibar" + if registryEntry.command.startsWith "Vomnibar." chrome.tabs.sendMessage sender.tab.id, name: "openVomnibar", sourceFrameId: frameId, registryEntry: registryEntry else if registryEntry.passCountToFunction -- cgit v1.2.3 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 From 201451d94edefa8c873d417f5f6190d993204b5e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 1 Mar 2016 13:13:08 +0000 Subject: Key bindings; move Vomnibar commands back to content scripts. --- background_scripts/commands.coffee | 14 +++++++------- background_scripts/main.coffee | 5 +---- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 25acdc03..4dbcd1cd 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -381,13 +381,13 @@ commandDescriptions = moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true }] # These are background-page commands because all requests go via the background page. - "Vomnibar.activate": ["Open URL, bookmark, or history entry", { background: true, noRepeat: true }] - "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { background: true, noRepeat: true }] - "Vomnibar.activateTabSelection": ["Search through your open tabs", { background: true, noRepeat: true }] - "Vomnibar.activateBookmarks": ["Open a bookmark", { background: true, noRepeat: true }] - "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { background: true, noRepeat: true }] - "Vomnibar.activateEditUrl": ["Edit the current URL", { background: true, noRepeat: true }] - "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { background: true, noRepeat: true }] + "Vomnibar.activate": ["Open URL, bookmark, or history entry", { noRepeat: true }] + "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { noRepeat: true }] + "Vomnibar.activateTabSelection": ["Search through your open tabs", { noRepeat: true }] + "Vomnibar.activateBookmarks": ["Open a bookmark", { noRepeat: true }] + "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { noRepeat: true }] + "Vomnibar.activateEditUrl": ["Edit the current URL", { noRepeat: true }] + "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { noRepeat: true }] nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }] mainFrame: ["Select the tab's main/top frame", { background: true, noRepeat: true }] diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 614b74c0..49199cae 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -370,10 +370,7 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> # End action functions runBackgroundCommand = ({frameId, registryEntry, count}, sender) -> - if registryEntry.command.startsWith "Vomnibar." - chrome.tabs.sendMessage sender.tab.id, - name: "openVomnibar", sourceFrameId: frameId, registryEntry: registryEntry - else if registryEntry.passCountToFunction + if registryEntry.passCountToFunction BackgroundCommands[registryEntry.command] count, frameId else if registryEntry.noRepeat BackgroundCommands[registryEntry.command] frameId -- cgit v1.2.3 From 5db79c7e8ef05bea07d1e811de4c9a7755be85f2 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 1 Mar 2016 13:31:51 +0000 Subject: Key bindings; and one more tiny tweak. --- background_scripts/commands.coffee | 1 - 1 file changed, 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 4dbcd1cd..08b8f449 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -380,7 +380,6 @@ commandDescriptions = moveTabLeft: ["Move tab to the left", { background: true, passCountToFunction: true }] moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true }] - # These are background-page commands because all requests go via the background page. "Vomnibar.activate": ["Open URL, bookmark, or history entry", { noRepeat: true }] "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { noRepeat: true }] "Vomnibar.activateTabSelection": ["Search through your open tabs", { noRepeat: true }] -- cgit v1.2.3 From 177a12ca5ccfd08ca5576575611907bfd1f7f34f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 2 Mar 2016 10:26:38 +0000 Subject: Key bindings; document Commands.generateKeyStateMapping(). --- background_scripts/commands.coffee | 1 + 1 file changed, 1 insertion(+) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 08b8f449..7429b6f0 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -101,6 +101,7 @@ Commands = @keyToCommandRegistry = {} @mapKeyToCommand { key, command } for own key, command of defaultKeyMappings + # This generates a nested key-to-command mapping structure. There is an example in mode_key_handler.coffee. 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 -- cgit v1.2.3