From 17e233a2bdbb725a14b9aa363ed659a5bd9feeb2 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 10:30:25 +0100 Subject: Pass command's registry entry to content script. --- content_scripts/vimium_frontend.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 41fb772b..6b27924d 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -314,7 +314,7 @@ executePageCommand = (request) -> # All other commands are handled in their frame (but only if Vimium is enabled). return unless frameId == request.frameId and isEnabledForUrl - if (request.passCountToFunction) + if request.registryEntry.passCountToFunction Utils.invokeCommandString(request.command, [request.count]) else Utils.invokeCommandString(request.command) for i in [0...request.count] -- cgit v1.2.3 From bd3cf0386a88d5878ee352c4d0c80005eaf2a93a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 10:33:30 +0100 Subject: Pass the command's registry entry to vomnibar commands. --- content_scripts/vimium_frontend.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 6b27924d..8c6dd374 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -307,7 +307,7 @@ executePageCommand = (request) -> if DomUtils.isTopFrame() # We pass the frameId from request. That's the frame which originated the request, so that's the frame # which should receive the focus when the vomnibar closes. - Utils.invokeCommandString request.command, [ request.frameId ] + Utils.invokeCommandString request.command, [ request.frameId, request.registryEntry ] refreshCompletionKeys request return -- cgit v1.2.3 From 087f7e8d180c9048ee32bdb243eabe2c15021fc7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 10:58:34 +0100 Subject: Implement pre-population of custom-search keywords. Now, a mapping of the form: map s vomnibar.activate keyword=g makes the vomnibar open (on "s") with the Google custom-search engine activated immediately (assuming it's configured). The corresponding custom search-engine configuration would be: g: http://www.google.com/search?q=%s Google --- content_scripts/vomnibar.coffee | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 2529c077..76698634 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -4,14 +4,22 @@ Vomnibar = vomnibarUI: null + getOptions: (registryEntry = { extras: [] }) -> + extras = {} + for extra in registryEntry.extras + [ key, value ] = extra.split "=" + extras.query = "#{value} " if key? and key == "keyword" and value? and 0 < value.length + extras + # sourceFrameId here (and below) is the ID of the frame from which this request originates, which may be different # from the current frame. - activate: (sourceFrameId) -> @open sourceFrameId, {completer:"omni"} - activateInNewTab: (sourceFrameId) -> @open sourceFrameId, { - completer: "omni" - selectFirst: false - newTab: true - } + + activate: (sourceFrameId, registryEntry) -> + @open sourceFrameId, extend @getOptions(registryEntry), completer:"omni" + + activateInNewTab: (sourceFrameId, registryEntry) -> + @open sourceFrameId, extend @getOptions(registryEntry), completer: "omni", newTab: true + activateTabSelection: (sourceFrameId) -> @open sourceFrameId, { completer: "tabs" selectFirst: true -- cgit v1.2.3 From 6a97f4cf5e1f1c21336d2fce9da20c3bc5633d05 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 14:20:19 +0100 Subject: Prepopulate @customSearchMode in vomnibar. This avoids a flicker whereby the keyword is first inserted into the input, then removed. --- content_scripts/vomnibar.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 76698634..d46b2daf 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -8,7 +8,7 @@ Vomnibar = extras = {} for extra in registryEntry.extras [ key, value ] = extra.split "=" - extras.query = "#{value} " if key? and key == "keyword" and value? and 0 < value.length + extras.keyword = value if key? and key == "keyword" and value? and 0 < value.length extras # sourceFrameId here (and below) is the ID of the frame from which this request originates, which may be different -- cgit v1.2.3 From 97bfe5f039ae9044fc634448ad3a97b1cdc05792 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 17:06:55 +0100 Subject: Verify keyword for custom search-engine activation. For ... map s Vomnibar.activate keyword=g ... we verify that "g" is indeed a custom search-engine keyword before setting it. If it is not, we output a console.log message and launch a vanilla vomnibar. (An alternative would be to bail.) --- content_scripts/vimium_frontend.coffee | 1 + content_scripts/vomnibar.coffee | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 8c6dd374..005412e5 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -62,6 +62,7 @@ settings = helpDialog_showAdvancedCommands: null smoothScroll: null grabBackFocus: null + searchEngines: null init: -> @port = chrome.runtime.connect name: "settings" diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index d46b2daf..06b546a6 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -4,21 +4,35 @@ Vomnibar = vomnibarUI: null - getOptions: (registryEntry = { extras: [] }) -> - extras = {} - for extra in registryEntry.extras - [ key, value ] = extra.split "=" - extras.keyword = value if key? and key == "keyword" and value? and 0 < value.length - extras + # Parse any additional options from the command's registry entry. Currently, this only includes a flag of + # the form "keyword=X", for direct activation of a custom search engine. + parseRegistryEntry: (registryEntry = { extras: [] }, callback = null) -> + options = {} + searchEngines = settings.get("searchEngines") ? "" + SearchEngines.refreshAndUse searchEngines, (engines) -> + for extra in registryEntry.extras + [ key, value ] = extra.split "=" + switch key + when "keyword" + if value? and engines[value]? + options.keyword = value + else + console.log "Vimium configuration error: no such custom search engine: #{extra}." + else + console.log "Vimium configuration error: unused flag: #{extra}." + + callback? options # sourceFrameId here (and below) is the ID of the frame from which this request originates, which may be different # from the current frame. activate: (sourceFrameId, registryEntry) -> - @open sourceFrameId, extend @getOptions(registryEntry), completer:"omni" + @parseRegistryEntry registryEntry, (options) => + @open sourceFrameId, extend options, completer:"omni" activateInNewTab: (sourceFrameId, registryEntry) -> - @open sourceFrameId, extend @getOptions(registryEntry), completer: "omni", newTab: true + @parseRegistryEntry registryEntry, (options) => + @open sourceFrameId, extend options, completer:"omni", newTab: true activateTabSelection: (sourceFrameId) -> @open sourceFrameId, { completer: "tabs" -- cgit v1.2.3 From 5930a6e3510f2bd052771601581aa410728d68e3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 30 May 2015 06:16:24 +0100 Subject: Use the term "options" instead of "flags" for command options. "Flags" implies binary toggles. The term "options" seems more consistent with what's actually going on here. --- content_scripts/vomnibar.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 06b546a6..4bd8e8fd 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -6,20 +6,20 @@ Vomnibar = # Parse any additional options from the command's registry entry. Currently, this only includes a flag of # the form "keyword=X", for direct activation of a custom search engine. - parseRegistryEntry: (registryEntry = { extras: [] }, callback = null) -> + parseRegistryEntry: (registryEntry = { options: [] }, callback = null) -> options = {} searchEngines = settings.get("searchEngines") ? "" SearchEngines.refreshAndUse searchEngines, (engines) -> - for extra in registryEntry.extras - [ key, value ] = extra.split "=" + for option in registryEntry.options + [ key, value ] = option.split "=" switch key when "keyword" if value? and engines[value]? options.keyword = value else - console.log "Vimium configuration error: no such custom search engine: #{extra}." + console.log "Vimium configuration error: no such custom search engine: #{option}." else - console.log "Vimium configuration error: unused flag: #{extra}." + console.log "Vimium configuration error: unused flag: #{option}." callback? options -- cgit v1.2.3