Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP

  • Loading branch information...
commit 9e4eb346bee9b4d7136782cb8f4ebdd0ed9c0add 1 parent e1c6290
@int3 int3 authored
View
10 background_page.html
@@ -620,7 +620,9 @@
if (!registryEntry.isBackgroundCommand) {
var port = chrome.tabs.connect(tabId, { name: "executePageCommand" });
- port.postMessage({ command: registryEntry.command,
+ console.log(registryEntry);
+ port.postMessage({ command: registryEntry.fn,
+ kwargs: registryEntry.kwargs,
frameId: frameId,
count: count,
passCountToFunction: registryEntry.passCountToFunction,
@@ -630,9 +632,11 @@
refreshedCompletionKeys = true;
} else {
if(registryEntry.passCountToFunction){
- this[registryEntry.command](count);
+ // TODO pass args
+ this[registryEntry.fn](count);
} else {
- repeatFunction(this[registryEntry.command], count, 0, frameId);
+ // TODO pass args
+ repeatFunction(this[registryEntry.fn], count, 0, frameId);
}
}
View
25 background_scripts/commands.coffee
@@ -23,14 +23,19 @@ Commands =
passCountToFunction: options.passCountToFunction
mapKeyToCommand: (key, command) ->
- unless @availableCommands[command]
- console.log(command, "doesn't exist!")
+ [commandFn, commandKwargsStr] = command.split /\s+/
+ # we could use JSON.parse, but `eval` allows for unquoted keys
+ commandKwargs = if commandKwargsStr? then JSON.parse commandKwargs else []
+
+ unless @availableCommands[commandFn]
+ console.log(commandFn, "doesn't exist!")
return
@keyToCommandRegistry[key] =
- command: command
- isBackgroundCommand: @availableCommands[command].isBackgroundCommand
- passCountToFunction: @availableCommands[command].passCountToFunction
+ fn: commandFn
+ kwargs: commandKwargs
+ isBackgroundCommand: @availableCommands[commandFn].isBackgroundCommand
+ passCountToFunction: @availableCommands[commandFn].passCountToFunction
unmapKey: (key) -> delete @keyToCommandRegistry[key]
@@ -59,9 +64,7 @@ Commands =
if (lineCommand == "map")
continue if (splitLine.length != 3)
key = @normalizeKey(splitLine[1])
- vimiumCommand = splitLine[2]
-
- continue unless @availableCommands[vimiumCommand]
+ vimiumCommand = splitLine[2..]
console.log("Mapping", key, "to", vimiumCommand)
@mapKeyToCommand(key, vimiumCommand)
@@ -90,7 +93,7 @@ Commands =
"reload", "toggleViewSource", "copyCurrentUrl", "LinkHints.activateModeToCopyLinkUrl",
"openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp",
"enterInsertMode", "focusInput",
- "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab", "LinkHints.activateModeWithQueue",
+ "LinkHints.activateMode", 'LinkHints.activateMode {"openInNewTab":true}', "LinkHints.activateModeWithQueue",
"Vomnibar.activate", "Vomnibar.activateWithCurrentUrl", "Vomnibar.activateTabSelection",
"Vomnibar.activateBookmarks",
"goPrevious", "goNext", "nextFrame"]
@@ -137,7 +140,7 @@ defaultKeyMappings =
"gi": "focusInput"
"f": "LinkHints.activateMode"
- "F": "LinkHints.activateModeToOpenInNewTab"
+ 'F': 'LinkHints.activateMode {"openInNewTab":true}'
"<a-f>": "LinkHints.activateModeWithQueue"
"/": "enterFindMode"
@@ -205,7 +208,7 @@ commandDescriptions =
focusInput: ["Focus the first (or n-th) text box on the page", { passCountToFunction: true }]
'LinkHints.activateMode': ["Open a link in the current tab"]
- 'LinkHints.activateModeToOpenInNewTab': ["Open a link in a new tab"]
+ 'LinkHints.activateMode {"openInNewTab": true}': ["Open a link in a new tab"]
'LinkHints.activateModeWithQueue': ["Open multiple links in a new tab"]
enterFindMode: ["Enter find mode"]
View
10 content_scripts/link_hints.coffee
@@ -40,11 +40,13 @@ LinkHints =
"@contenteditable='' or translate(@contenteditable, 'TRUE', 'true')='true']"])
# We need this as a top-level function because our command system doesn't yet support arguments.
- activateModeToOpenInNewTab: -> @activateMode(true, false, false)
- activateModeToCopyLinkUrl: -> @activateMode(null, false, true)
- activateModeWithQueue: -> @activateMode(true, true, false)
+ activateModeToOpenInNewTab: -> @activateMode(openInNewTab: true)
+ activateModeToCopyLinkUrl: -> @activateMode(copyLinkUrl: true)
+ activateModeWithQueue: -> @activateMode(openInNewTab: true, withQueue: true)
- activateMode: (openInNewTab, withQueue, copyLinkUrl) ->
+ activateMode: (kwargs) ->
+ kwargs ?= {}
+ {openInNewTab, withQueue, copyLinkUrl} = kwargs
if (!document.getElementById("vimiumLinkHintCss"))
# linkHintCss is declared by vimiumFrontend.js and contains the user supplied css overrides.
addCssToPage(linkHintCss, "vimiumLinkHintCss")
View
12 content_scripts/vimium_frontend.coffee
@@ -129,14 +129,14 @@ initializePreDomReady = ->
chrome.extension.onConnect.addListener (port, name) ->
if (port.name == "executePageCommand")
- port.onMessage.addListener (args) ->
- if (frameId == args.frameId)
- if (args.passCountToFunction)
- Utils.invokeCommandString(args.command, [args.count])
+ port.onMessage.addListener (commandInfo) ->
+ if (frameId == commandInfo.frameId)
+ if (commandInfo.passCountToFunction)
+ Utils.invokeCommandString(commandInfo.command, [commandInfo.count, commandInfo.kwargs])
else
- Utils.invokeCommandString(args.command) for i in [0...args.count]
+ Utils.invokeCommandString(commandInfo.command, [commandInfo.kwargs]) for i in [0...commandInfo.count]
- refreshCompletionKeys(args)
+ refreshCompletionKeys(commandInfo)
else if (port.name == "getScrollPosition")
port.onMessage.addListener (args) ->
scrollPort = chrome.extension.connect({ name: "returnScrollPosition" })
Please sign in to comment.
Something went wrong with that request. Please try again.